Save state radio button javascript-html -
i´m trying program save state of radio button , check it. code don´t know it`s wrong. me please
<script> function savestate(){ var ans1 = document.getelementbyid('grupo1'); if (ans1.value == 1) { ans1.setattribute("checked","checked"); ans1.checked = true; } </script> <input type="radio" name="group" id="grupo1" value="1"> 1 <input type="radio" name="group" id="grupo2" value="0"> 2 <input type="submit" onclick="savestate()" value="update">
try this:
<script> function savestate(){ var ans1 = document.queryselector('input[name="group"]:checked').value; if (ans1.value == 1){ ans1.setattribute("checked","checked"); ans1.checked = true; } } </script>
Comments
Post a Comment