Hiren
Hiren

Reputation:

Struts2 select tag add/remove values using javascript

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

<s:select label="Select Month" 
name="monthname" 
headerKey="1"
headerValue="-- Please Select --"
list="#{'01':'January','02':'February','03':'March','04':'April',
        '05':'May','06':'June','07':'July','08':'August','09':'September','10':
        'October','11':'November','12':'December'}"
/>

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.

Upvotes: 0

Views: 4040

Answers (1)

cgp
cgp

Reputation: 41381

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

Upvotes: 1

Related Questions