Trying to check my switches, but it just doesn't work

I am an extreme beginner in terms of checking Java script, so I won’t be surprised if literally everything in my code is wrong.

I am trying to check my switches.

I previously used this format to try to do this:

if (document.ExamEntry.GCSE.checked == true) {
confirm("You have selected GCSE. Is this correct?");
if (document.ExamEntry.A2.checked == true) {
confirm("You have selected GCSE. Is this correct?");
if (document.ExamEntry.A2.checked == true) {
confirm("You have selected A2. Is this correct?");

because I want it to give a message for each switch, but of course it didn't work. (The sumbit button worked as a redirect to the next page, but the cancel button did the same thing as it didn’t receive a command that I didn’t know how to do) I was told that the onClick command would be good, but I tried it still failed, because I was not sure how to apply it.

So, I tried to do this: (my new code)

functioncheckRadio  () {
        var level = "";
        var qualification = document.ExamEntry.Rbutton.value;
        var i;

        for (i=0; i <qualification; i++) {
            if (document.ExamEntry.qualification[i].checked) {
                    level = document.ExamEntry.Rbutton.value;
                    break;
            }
        }
        if (level == "") {
            document.getElementById("Rbutton").innerHTML = "You must
            select a qualification level";
            return false;
        }
        else {
            document.getElementById("Rbutton").innerHTML = "";
            return = true;
        }
    }

and this is my html:

  <td id="RadioGCSE">GCSE</td>
  <td><input type="radio" name="Rbutton" value="GCSE" id="r1" checked = "checked" /></td>
  <tr>
  <td id="RadioAS">AS</td>
  <td><input type="radio" name="Rbutton" value="AS" id="r2" /></td>
  </tr>
  <td id="RadioA2">A2</td>
  <td><input type="radio" name="Rbutton" value="A2" id="r3" /></td>
  <tr>

, . : GCSE, : " GCSE. " , , , , .

/​​ . - .

+4
2

.

<td id="RadioGCSE">GCSE</td>
  <td><input type="radio" id="Rbutton1" name="Rbutton1" value="GCSE" id="r1" checked = "checked" /></td>
  <tr>
  <td id="RadioAS">AS</td>
  <td><input type="radio" id="Rbutton2" name="Rbutton2" value="AS" id="r2" /></td>
  </tr>
  <td id="RadioA2">A2</td>
  <td><input type="radio" id="Rbutton3" name="Rbutton2" value="A2" id="r3" /></td>
  <tr>

"getElementsByName" , "getElementById"

if (document.getElementById('Rbutton1').checked == true) {
    confirm("You have selected GCSE. Is this correct?");
}
if (document.getElementById('Rbutton2').checked == true) {
    confirm("You have selected GCSE. Is this correct?");
}
if (document.getElementById('Rbutton3').checked == true) {
    confirm("You have selected A2. Is this correct?");
}

: http://jsfiddle.net/rv9uu/2/

0

, . .

Script:

<script type="text/javascript" language="javascript">
<!--
function CheckRadio() {
     var rdio = document.getElementsByTagName('input');

     for (var i=0; i<rdio.length; i++) {
      if (rdio[i].type == 'radio' && rdio[i].checked) {
          alert("You selected " + rdio[i].value); }
     }
}
-->
</script>

HTML:

<form method="post" action="">
    <input type="radio" name="Rbutton" value="GCSE" id="r1" />GCSE<br />
    <input type="radio" name="Rbutton" value="AS" id="r2" />AS<br />
    <input type="radio" name="Rbutton" value="A2" id="r3" />A2<br /><br />
    <input type="button" name="btn" value="Submit" onclick="javascript: CheckRadio()">
</form>
0

All Articles