Monday, September 28, 2015

when radio button is selected, a popup box should display the text of the radio button

<script type="text/javascript">
function radioEvent(form) 
{
 for (var i = 0; i < form.radioButton.length; i++) 
 {
    if (form.radioButton[i].checked)
    {
        alert("You chose " + form.radioButton[i].value + ".")
    }
 }
 }
</script>
</head>
<body>
<form>
<input type="radio" name= "radioButton" value= "Excellent"   onclick="radioEvent(this.form);"/> Excellent<br/>
<input type="radio" name="radioButton"  value="Very Good" onclick="radioEvent(this.form);"/> Very Good <br/>
<input type="radio" name="radioButton"  value="Good" onclick="radioEvent(this.form);"/> Good <br/>
<input type="radio" name="radioButton"  value="Satisfactory" onclick="radioEvent(this.form);"/> Satisfactory
</form>
</body>
</html>
shareimprove this answer
   
Thank you for the above code.Is it the same procedure for drop-down box, check box and text input too? – Navya Akkiraju Oct 13 '12 at 23:14 
   
yes, just change type of Input tag –  vinus patel Oct 15 '12 at 1:43