javascript - How to pass value of radio button to another form field using jquery? -
i want pass value either no
or 1
input name="auth[]"
below.
<td> send <input type="radio" name="authorized[]'.$c.'" id="send'.$c.'"value="1" checked> </td> <td> no <input label="no" type="radio" name="authorized[]'.$c.'" id="no'.$c.'"value="no" > <input name="auth[]" type="hidden" class="mailclass" id="auth'.$c.'" value="" /> </td>
this code pass no
value, if reverse decision , re-select send, not switch value 1
.
$(document).ready(function() { var x='1' $( "input:radio" ).each(function() { $(this).click(function() { x=$(this).val(); alert(x); $(this).next('.mailclass').val(x); }) }) })
it's selector. $(this).next...
isn't working. using click
more better coding each
did this:
var x='1'; $( "input:radio" ).click(function() { x=$(this).val(); $('input.mailclass').val(x); }) });
and, here's working jsfiddle.
hope helps! (disclaimer: can see small part of code, root cause selector. feel free use better selector if mine isn't optimal. :-)
Comments
Post a Comment