HTML button

0

Czy idzie, a jeśli tak aby po kliknięciu buttona zaznaczał się kolejny element Radio Buttona, a standardowo zaznaczamy pierwszy, jeśli nie było zaznaczenia?

<!DOCTYPE html>
<html>
<body>

                        <input type="radio" name="animal" value="Cat" />Cats<br />
                        <input type="radio" name="animal" value="Dog" />Dogs<br />
                        <input type="radio" name="animal" value="Bird" />Birds<br />

                        <button type="button" onclick="alert('Hello world!')">Click Me!</button>

</body>
</html>
0

OK, mam już rozwiązanie poniższe ale jest problemowe.

jak się pozbyć 'taga' form aby to dalej działało?

<!DOCTYPE html>
<html>
<head>
<script>
function check() {  document.getElementById("red").checked=true }
function uncheck(){ document.getElementById("red").checked=false }

function checkNext()
{

   for (var i=0; i < document.ord.colors.length; i++)
   {
      if (document.ord.colors[i].checked)
      {
         if(i===document.ord.colors.length-1)
         {
           document.ord.colors[0].checked=true;
           
         }else{
           document.ord.colors[i+1].checked=true;
         }
         break;
      }
   }
}

</script>
</head>
<body>

<form name="ord">
What color do you prefer?<br>
<input type="radio" name="colors" id="red" checked=true >Red<br>
<input type="radio" name="colors" id="blue">Blue<br>
<input type="radio" name="colors" id="green">Green

<button type="button" onclick="checkNext()">Next</button>

</form>

<button type="button" onclick="check()">Check "Red"</button>
<button type="button" onclick="uncheck()">Uncheck "Red"</button>


</body>
</html>

 
0

Dobra też już mam.
Dzieki za pomoc.
Daje tu, moze jeszcze komus sie przyda.

 <!DOCTYPE html>
<html>
<head>
<script>
function checkNext()
{

    var radioButtons = document.getElementsByName("colors");
    for (var i = 0; i < radioButtons.length; i++) {
        if (radioButtons[i].checked) {
         if(i===radioButtons.length-1)
         {
           radioButtons[0].checked=true;
           
         }else{
           radioButtons[i+1].checked=true;
         }
         break;
        }
    }

}

</script>
</head>
<body>

What color do you prefer?<br>
<input type="radio" name="colors" id="red" checked=true >Red<br>
<input type="radio" name="colors" id="blue">Blue<br>
<input type="radio" name="colors" id="green">Green

<button type="button" onclick="checkNext()">Next</button>


</body>
</html>

1 użytkowników online, w tym zalogowanych: 0, gości: 1