Question

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

Was it helpful?

Solution

You can do:

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

Good luck!

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top