How to select radio buttons in jquery -
the code below adds value textbox:
$('#maintxtweight').val(textweight);
but want know how can select radio button depending on value using jquery?
below radio buttons:
<table id="replies"> <tr> <th colspan="2">replies</th> </tr> <tr> <td>number of replies:</td> <td align="left"> <div class="replytd"> <label> <input type="radio" name="reply" id="singlebtn " value="single" class="replybtn" />single</label> </div> <div class="replytd"> <label> <input type="radio" name="reply" id="multiplebtn" value="multiple" class="replybtn" />multiple</label> </div> </td> </tr> </table>
i have created if statement below, need being able select "single" radio button if reply type equals "single", or select "multiple" radio button if reply type equals "multiple".
below if statement:
if(reply == "single") { //select "single" radio button } else if(reply == "multiple") { //select "multiple" radio button }
i want exact same thing occur line of code again "single" , "multiple" radio buttons:
var $btnreply = "<input type='radio' name='reply[" + count + "]' value='single' class='replybtnrow' /> single<br /><input type='radio' name='reply[" + count + "]' value='multiple' class='replybtnrow' /> multiple"; $replies.children().append($btnreply); if($("input[name=reply]:checked").length) { $replies.find('input[name="reply[' + count + ']"]').eq($("input[name=reply]:checked").val() == "single" ? 0 : 1).prop("checked", true); }
update:
function addwindow(reply) { if($(plusbutton_clicked).attr('id')=='mainplusbutton') { $('input[value="'+reply.tolowercase()+'"]').attr('checked', true); } else { $(plusbutton_clicked).closest('tr').find('input[value="'+reply.tolowercase()+'"]').attr('checked', true); } $.modal.close(); return false; }
if trying radio button has value of what's in reply, if understand question correctly, can try this
$('input[value="'+reply.tolowercase()+'"]')รข.attr('checked', true)
assuming reply 'single' or 'multiple'
Comments
Post a Comment