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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -