1

I want to get a radio button to display an alert when it is selcted, so the user can check that they have chosen the correct value. This is the code I have for the radio buttons:

 <tr>
     <td><input type="radio" name="level" id="GCSE" value="GCSE">GCSE<br>
    <input type="radio" name="level" id="AS" value="AS">AS<br>
    <input type="radio" name="level" id="A2" value="A2">A2</td>
 </tr>

How would I get so when any of these radio buttons are selected an alert is displayed to the user saying: "Are you sure you have chosen the correct entry level?"

Please keep answers simple, as I have only been learning HTML for 3 weeks

user3248841
  • 13
  • 1
  • 1
  • 3
  • Read the answer of this post http://stackoverflow.com/questions/14957604/javascript-radio-button-confirmation Possible duplicate? – Zzyrk Jan 29 '14 at 12:53

2 Answers2

2

You can do:

<input type="radio" name="level" id="GCSE" value="GCSE" onclick="alert('test');" />

Good luck!

Eitan
  • 1,286
  • 2
  • 16
  • 55
1

let's assume you have a form called # Myform

Then your code will be like this:

<form id="myForm">
<input type="radio" name="level" id="GCSE" value="GCSE" /> GCSE <br />
<input type="radio" name="level" id="AS" value="AS" /> AS <br />
<input type="radio" name="level"  id="A2" value="A2" /> A2 <br />
</form>

Then, put in a tag script something like this:

<script>
$('#myForm input').on('change', function() {
   alert("Are you sure you have chosen the correct entry level? +"$('input[name=level]:checked', '#myForm').val()); 
});
</scritp>

Hope this works for you!

Thx