Skip to content
Advertisement

Multiselect options with each option selecting multiple times using jquery

Select numbers (you can select each number any number of times):

 <select name="number_selection" method="post" id="number_selection" >
  <option value="0">0</option>
  <option value="1">1 </option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<input type="button" value="Select" id="select_button"/> 


 <div id="feedback"> </div>

what I’ve tried in jquery is this….

$('#select_button').click(function(){
    var gs= $('#number_selection').val();
    $('#feedback').html(gs);            
    });

Now, What i am trying to do is, if i select a number from the options, it should display in the ‘div’ and if i select another number or the same number again, it should display beside the first number, but i am only able to select only a single number, not multiple numbers. I want the do this using jquery

If you don’t understand my problem, i can explain you further. Please help.

And also if I want to deselect each element from the list appended? I’ve tried this… but isn’t working.

$('#select_button').click(function(){
    var gs= $('#number_selection').val();
    $('#feedback').append(gs + '  ' + '<input type="button" value="Remove" id="gs_remove" />' + '<br>');

    });

    $('#gs_remove').click(function(){
    (this).hide();
    });

but with this i am not able to remove each selected option.

Advertisement

Answer

Replace

 $('#fcb_pt_gs').html(gs);

by

 $('#fcb_pt_gs').append(gs);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement