Click to See Complete Forum and Search --> : onclick event
blveit
12-12-2003, 07:34 AM
I'm trying to do a simple alert on radio buttons, but keeps getting undefined. I try to put the form name on instead of "forms[0], but it still does not work. Any insight on this will help. Thanks
This is the two radio buttons.
<INPUT type="radio" id="radioq2" name="radioq2" value="firstvisit" onclick="javascript:alert(document.forms[0].radioq2.value)">
<INPUT type="radio" id="radioq2" name="radioq2" value="everyday" onclick="javascript:alert(document.forms[0].radioq2.value)">
lcscne
12-12-2003, 07:38 AM
I'm no guru but I've seen me.value before in these situations.
damon2003
12-12-2003, 07:40 AM
you have spaces in java script
should be javascript
lcscne
12-12-2003, 08:10 AM
oops im sorry, i think its this.value. getting my languages mixed up here.
blveit
12-12-2003, 08:23 AM
I don't have a space in javascript. It just copy in that way.
ray326
12-12-2003, 08:39 AM
Originally posted by damon2003
you have spaces in java script
should be javascript
The stupid BBS does that to^H^Hfor you. It's a feature. Yea, right.
olerag
12-12-2003, 08:41 AM
2 Examples here - the second embeds in the html object, as
your were attempting.
In your attempt, you probably needed to include the radio
object's element position (either [0] or [1]) however
"this.value" is probably simpler.
And yes, the "javascript" appears to display in the thread
as "java script" but there is no space.
<html>
<head>
<script type="text/javascript">
function showRGValue() {
var rgObj = document.forms[0].radioTest1;
if (rgObj[0].checked) {;
alert(rgObj[0].value);
}
else {
alert(rgObj[1].value);
}
}
</script>
</head>
<body>
<center>
<b>Radio Test</b>
<form>
<input type="radio" name="radioTest1" value="firstvisit" onClick="showRGValue()">First Visit
<input type="radio" name="radioTest1" value="everyday" onClick="showRGValue()">Every Day
<p>
<input type="radio" name="radioTest2" value="firstvisit" onClick="javascript:alert(this.value)">First Visit
<input type="radio" name="radioTest2" value="everyday" onClick="javascript:alert(this.value)">Every Day
</form>
<hr>
</center>
</body>
</html>
blveit
12-12-2003, 09:10 AM
Thanks olerag! I will give it a try.