Can not check the radio button dynamically using Javascript/Jquery -
i need 1 help. need check radio button dynamically using javascript/jquery. explaining code below.
<div style="float:left; margin-right:10px;"> <input type="radio" name="answer_type0" id="answer_type0" onclick="selectscale(this.value,'0');" value="5736db13ed8cda709ffc8918">scale <input type="radio" name="answer_type0" id="answer_type0" onclick="selectscale(this.value,'0');" value="5736daffed8cda709ffc8917">yes/no <input type="radio" name="answer_type0" id="answer_type0" onclick="selectscale(this.value,'0');" value="5736db29ed8cda709ffc8919">written </div> <span> <button type="button" id="btn" name="btn" onclick="setradiobuttonvalue()">set</button> </span>
here 3 radio button available .when user click on set button 1 radio button should checked per given value. javascript code given below.
function setradiobuttonvalue(){ var valu="5736daffed8cda709ffc8917"; $('#answer_type0').val(valu).prop('checked', true); console.log('check',document.getelementbyid('answer_type0').checked); }
my updated code available here
here need check per given value(i.e-var valu="5736daffed8cda709ffc8917"
) per code yes/no
should checked in case first radio button checked.please me resolve issue.similarly need check multiple set of radio button each set. plunkr code here.
in case when loop complete set 2. if want loop see answer or can try simple approach adding class within divs.
var valu = ['5736daffed8cda709ffc8917', '5736db13ed8cda709ffc8918', '5736db29ed8cda709ffc8919'] function setradiobuttonvalue() { var = 0; $('.qclass').each(function() { console.log($(this).find('input[value="' + valu[i] + '"]').is(':checked')); $(this).find('input[value="' + valu[i] + '"]').prop('checked', true); i++; }) }
add class div containing radios in case qclass
var valu = ['5736daffed8cda709ffc8917', '5736db13ed8cda709ffc8918', '5736db29ed8cda709ffc8919'] function setradiobuttonvalue() { var = 0; $('.qclass').each(function() { $(this).find('input[value="' + valu[i] + '"]').prop('checked', true); console.log($(this).find('input[value="' + valu[i] + '"]').is(':checked')); i++; }) }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div style="float:left; margin-right:10px;" class="qclass"> <input type="radio" name="answer_type0" onclick="selectscale(this.value,'0');" value="5736db13ed8cda709ffc8918">scale <input type="radio" name="answer_type0" onclick="selectscale(this.value,'0');" value="5736daffed8cda709ffc8917">yes/no <input type="radio" name="answer_type0" onclick="selectscale(this.value,'0');" value="5736db29ed8cda709ffc8919">written </div> <br> <br> <div style="float:left; margin-right:10px;" class="qclass"> <input type="radio" name="answer_type1" onclick="selectscale(this.value,'0');" value="5736db13ed8cda709ffc8918">a <input type="radio" name="answer_type1" onclick="selectscale(this.value,'0');" value="5736daffed8cda709ffc8917">b <input type="radio" name="answer_type1" onclick="selectscale(this.value,'0');" value="5736db29ed8cda709ffc8919">c </div> <br> <br> <div style="float:left; margin-right:10px;" class="qclass"> <input type="radio" name="answer_type2" onclick="selectscale(this.value,'0');" value="5736db13ed8cda709ffc8918">male <input type="radio" name="answer_type2" onclick="selectscale(this.value,'0');" value="5736daffed8cda709ffc8917">female <input type="radio" name="answer_type2" onclick="selectscale(this.value,'0');" value="5736db29ed8cda709ffc8919">male+female </div> <span> <button type="button" id="btn" name="btn" onclick="setradiobuttonvalue()">set</button> </span>
Comments
Post a Comment