Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get select option id and change hidden input value

Tags:

jquery

I have a form with a select list. Each option also contains a dynamic id, which I need to capture and then use that to change a hidden input's value. So basically take the selected options id and change the value of a hidden input value.

My select and hidden input look like:

<select name="item_options" id="size">
<option value="20030" id="Universal">Universal (20030)</option>
<option value="4545456" id="Medium">Medium (4545456)</option>
<option value="15447" id="Large">Large (15447)</option>
</select>

<input type="hidden" name="item_options_name" value="Universal" id="changevalue" />

I had done some jQuery to capture the selected option's id, but I can't figure out how to use it to change my input's value.

like image 951
richardpixel Avatar asked Sep 28 '10 07:09

richardpixel


People also ask

How can remove hidden field value in jQuery?

in jquery: $('#hiddenfieldid'). val(''); Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM.


1 Answers

$('#size').change(function(){
   var id = $(this).find(':selected')[0].id;
   $('#changevalue').val(id);
})
like image 106
Reigel Avatar answered Oct 02 '22 02:10

Reigel