Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- appending a form element until comma is pressed
- $("#options_"+id).keyup(function(){
- var val_options = $('#options_'+id).val(); //user input is stored in the variable val_options
- var options = val_options.split(','); //input is exploded with a comma
- var len = options.length;
- for(var i =0;i<len;i++)
- {
- var drop_options = "<option id='option_'"+i+">"+options[i]+"</option>";
- $("#select_"+id).append(drop_options);
- }
- });
- $("#options_" + id).keyup(function(e) {
- var val_options = $(this).val(); // getting input values
- options = val_options.split(','); // getting all values as array
- // checking for comma
- if (val_optons.indexOf(',') >= 0 ) {
- // if comma found then start append
- var options = val_options.split(',');
- var drop_options = ''; // take an empty string
- // looping over all values with
- // input fields separated by comma
- for (var i = 0; i < options.length; i++) {
- // making string of all options
- drop_options += "<option id='option_'" + i + ">" + options[i] + "</option>";
- }
- // append all option to select
- // here .html() will remove all previous
- // options and append newly
- $("#select_" + id).html(drop_options);
- }
- });
- $("#options_"+id).keyup(function(event){
- if (event.which !== 188) { // 188 is the keycode for ','
- return; // Do nothing.
- }
- var $this = $(this),
- val_options = $this.val(),
- options = val_options.split(','),
- $dropdown = $("#select_"+id);
- $dropdown.empty();
- for(var i =0;i<options.length-1;i++) {
- $dropdown.append(
- "<option id='option_'"+i+">"+options[i]+"</option>"
- );
- }
- });
Add Comment
Please, Sign In to add comment