Click to See Complete Forum and Search --> : radio button OnClick statement
drgnfli4
06-06-2003, 02:41 PM
HELP!!!!!
I need to call a JavaScript function with a radio button. The OnClick statement is bringing up error messages. I know it can be done but I'm having a heck of a time remembering the right code.
PLEASE HELP!
Thanx:confused:
khaki
06-06-2003, 03:25 PM
hi drgnfli4...
i'm not sure if the problem is with your function or with the way you scripted the radio button or whatever...
but I use this:
<script type="text/javascript">
function yourFunc()
{
// whatever your function does goes here
}
</script>
<input type="radio" name="radioName" onclick="javascript:yourFunc()">
if you are still having problems...
you may want to post the code in the javascript forum.
;) k
EDIT:
Note that the space between "java" and "script" has been put there by the forum.
It is supposed to be one word
:)
How about getting the word javascript out of there altogether? It is not needed:
<script type="text/javascript">
function yourFunc()
{
// whatever your function does goes here
}
</script>
</head>
<body>
<input type="radio" name="radioName" onclick="yourFunc();">
khaki
06-06-2003, 03:50 PM
<script type="text/javascript">
khaki + javascript = inevitable correction
</script>
whenever i decide to answer a javascript question...
it requires that someone follow behind me with a mop
:rolleyes: k
drgnfli4
06-06-2003, 04:20 PM
thank you for the suggestions but the onclick is not working. I tried it both ways and nothing. I am getting an error message that says "Object doesn't support property or method".
the JS part looks like this:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var len = 0;
function textCounter(t){
len=t.value;
len=len.split(" ").join("").toString();
len=len.split("-").join("").toString();
len=len.length;
}
function price(size){
if (size==1) var a=.5;
if (size==2) var a=1;
if (size==3) var a=1.5;
if (size==4) var a=2;
if (size==5) var a=2.5;
if (size==6) var a=3;
if (size==7) var a=3.5;
if (size==8) var a=4;
if (size==9) var a=4.5;
if (size==10) var a=5;
if (size==11) var a=5.5;
if (size==12) var a=6;
parent.bottom.document.body.innerHTML="your total is: $"+ a * len;
}
var shad=1;
function shadow(pos){
if (pos==1)
shad=1;
else
shad=2;
parent.bottom.document.body.innerHTML="your total is: $"+ a * len * shad;
}
// End -->
</script>
the HTML part looks like this:
<TABLE border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2" height="111">
<TR>
<TD width="33%" align="center" height="39">
<INPUT type="radio" name="shadow" value="up_left" onclick="shadow(0);"><IMG border="0" src="images/shadow_upleft.gif" width="108" height="36"></TD>
<TD width="33%" align="center" height="39">
<INPUT type="radio" name="shadow" value="up" onclick="shadow(0);"><IMG border="0" src="images/shadow_up.gif" width="108" height="36"></TD>
<TD width="34%" align="center" height="39">
<INPUT type="radio" name="shadow" value="up_right" onclick="shadow(0);"><IMG border="0" src="images/shadow_upright.gif" width="108" height="36"></TD>
</TR>
<TR>
<TD width="33%" align="center" height="31">
<INPUT type="radio" name="shadow" value="left" OnClick="shadow(0)"><IMG border="0" src="images/shadow_left.gif" width="108" height="36"></TD>
<TD width="33%" align="center" height="31">
<P align="center">
<INPUT type="radio" name="shadow" value="none" checked OnClick="shadow(1)"><IMG border="0" src="images/shadow1.gif" width="93" height="64"></TD>
<TD width="34%" align="center" height="31">
<INPUT type="radio" name="shadow" value="right" OnClick="shadow(0)"><IMG border="0" src="images/shadow_right.gif" width="108" height="36"></TD>
</TR>
<TR>
<TD width="33%" align="center" height="39">
<INPUT type="radio" name="shadow" value="down_left" OnClick="shadow(0)"><IMG border="0" src="images/shadow_downleft.gif" width="108" height="36"></TD>
<TD width="33%" align="center" height="39">
<INPUT type="radio" name="shadow" value="down" OnClick="shadow(0)"><IMG border="0" src="images/shadow_down.gif" width="108" height="36"></TD>
<TD width="34%" align="center" height="39">
<INPUT type="radio" name="shadow" value="down_right" OnClick="shadow(0)"><IMG border="0" src="images/shadow_downright.gif" width="108" height="36"></TD>
</TR>
</TABLE>
thanx for any help you can offer.