javascript - How can we turn radio button checked when we type its input -
as see below, have radio button group has 3 options. last 1 text input. there way make last 1 checked when type in text box?
<input type='radio' name='result' value="0"/><label for="0">false</label><br/> <input type='radio' name='result' value="1"/><label for="1">true</label><br/> <input type='radio' name='result' value="2"/><label for="2"> <input type="text" placeholder="type result" name="result_answ"></label>
provided have jquery loaded use this:
<input type='radio' name='result' value="0"/><label for="0">false</label><br/> <input type='radio' name='result' value="1"/><label for="1">true</label><br/> <input type='radio' name='result' value="2"/><label for="2"> <input type="text" placeholder="type result" onkeyup="jquery(this).parent().prev().prop('checked', true)" name="result_answ"></label>
here demo:
http://jsfiddle.net/9q1j36cj/
edit: here non-jquery version:
<input type='radio' name='result' value="0"/><label for="0">false</label><br/> <input type='radio' name='result' value="1"/><label for="1">true</label><br/> <input type='radio' name='result' value="2"/><label for="2"> <input type="text" placeholder="type result" onkeyup="this.parentnode.previoussibling.checked = true" name="result_answ"></label>
Comments
Post a Comment