views:

2154

answers:

1

Hi Guys, I wanted to add/remove values from the list box using javascript in struts2. How could I do that?

Let's say I wanted to remove January from the list or add new month in list by javascript in struts2. how do I will implement it?

Thanks in advance.

  • Hiren
A: 

Struts2 has nothing to do with it.

I recommend you look at jQuery, because it makes this trivial:

<select>
 <option>Jan
 <option>Feb
 <option>Mar
 <option>Apr
 <option>Jun
</select>
<input type="button" id="removeJanuary" value="Remove January">

<script>
  $(function() {
   $('#removeJanuary').click(function() {
     $("option:contains('Jan')").remove();
   });
  });
</script>

See example: http://jsbin.com/ajoqa

altCognito