html - Obtain id value from radio button using jQuery -


problem:

to obtain id radio button using jquery on click or without. jquery should detect if value set , choose or choose upon click.

html code (scenario 1 - no selection made):

<th><input type="radio" name="itemquestion" id="1" value="11"></th> <th><input type="radio" name="itemquestion" id="2" value="12"></th> <th><input type="radio" name="itemquestion" id="3" value="13"></th> <th><input type="radio" name="itemquestion" id="4" value="14"></th> <th><input type="radio" name="itemquestion" id="5" value="15"></th> 

html code (scenario 2 - selection has been made):

<th><input type="radio" name="itemquestion" id="1" value="11"></th> <th><input type="radio" name="itemquestion" id="2" value="12" checked="checked"></th> <th><input type="radio" name="itemquestion" id="3" value="13"></th> <th><input type="radio" name="itemquestion" id="4" value="14"></th> <th><input type="radio" name="itemquestion" id="5" value="15"></th> 

jquery code:

$('input[type=radio]', $('#itembuttons')).click(     function() {         var pos = $(this).parent().index() + 1;         $('#itemresponse').val(pos);     } ); 

question:

how can jquery modified in addition act on click() detect radio button has been checked on submit , return id (in case it's 2)? in other words, user can submit form without clicking radio button want #itemresponse contain id value 2.

if want populated before user clicks on radio button, add set value when page loaded:

$(document).ready(function () {     var selected_id = $('form input[type=radio]:checked').attr("id");     $('#itemresponse').val(selected_id); } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -