...

View Full Version : Radio Button OnClick



metroid
08-14-2008, 06:37 AM
I am trying to make it to where when people select a certain radio option, they get a message below the form.

I am terrible at explaining things. So here is a picture. http://img229.imageshack.us/img229/2419/explanationcg7.jpg

Philip M
08-14-2008, 09:30 AM
Try this:-



<span id = "message">Initial message if any</span><br><br><br>

<form name = "myform">
<input type = "radio" name = "rad1" id = "rad1" value = "Opt1" onclick = "showMessage()"> Option 1
<input type = "radio" name = "rad1" id = "rad1" value = "Opt2" onclick = "showMessage()"> Option 2
</form>

<script type = "text/javascript">

function showMessage() {

var mess1 = "Message appropriate to Option 1"
var mess2 = "Message appropriate to Option 2"

if (document.myform.rad1[0].checked) {
document.getElementById("message").innerHTML = mess1;
}
else if (document.myform.rad1[1].checked) {
document.getElementById("message").innerHTML = mess2;
}

}
</script>


It is not as cold as it was yesterday, but that's probably because it's a bit warmer. - Sports commentator



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum