Radio Buttons again - My function still does not work

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

I think that first i=0 command is a stray command, it is in a spot between the funtion declaration and the start of the function. I think you can remove it.

In the if command below that, I think you need i==0 there, ie:

for(i==0; i<document.myForm.radios.length;i++)

They have: 11 posts

Joined: Sep 1999

I still cant get this to work...
Any Suggestions on my check function? Thanks

function check()
{
if (document.myForm.radio[0].checked) {alert("yes")
} else {alert("dork")}
}

<form NAME="myForm">
<INPUT TYPE="radio" NAME="splitter" VALUE="tp" >Top Page Display<p>
<input type="radio" NAME="splitter" VALUE="bp" >Bottom Page Display
</form>
<form>
<input type="button" value="send it"
onClick="(check())"><P>
</form >

They have: 5,633 posts

Joined: Jan 1970

INSERT BETWEEN <SCRIPT></SCRIPT> TAGS:-

function check() {
for (i=0; i<document.myForm.splitter.length; i++) {
if (document.myForm.splitter[i].checked) {
var selectedRadioIndex = i;
}
}
if (selectedRadioIndex == 0) {
// Top Page Display script
}
else {
// Bottom Page Display script
}
}

INSERT BETWEEN <BODY></BODY> TAGS:-

<form name="myForm">
<input type="radio" name="splitter" checked>Top Page Display<br>
<input type="radio" name="splitter">Bottom Page Display<br>
<input type="button" value="send it" onClick="javascript:check()"><br>
</form>

----------
[email protected]
http://go.to/hass

They have: 11 posts

Joined: Sep 1999

You are a JavaScript GOD...sorry you had to spell it out for me, I still really don't understand why the other one I wrote didn't work but I really appreciate your help!

They have: 5,633 posts

Joined: Jan 1970

<zman> I don't know why the yours didn't work because it looked OK to me but I didn't run it myself - I just pasted the script that I use when checking radio buttons.

They have: 11 posts

Joined: Sep 1999

Thanks again, mine looked good to me too but thats how this stuff is, you can look and look and just not get it! Thats why forums like this are so valuable, I hope to be a contributor as well when I get better!

They have: 11 posts

Joined: Sep 1999

It was meant to check to see if a radio button was checked, then perform a function. I always use alert boxes to check the integrity of my logic before hooking up to another function. The heart of my problem was identifying the radio button checked object. that turned out to be document.myForm.splitter[0].checked

They have: 2,390 posts

Joined: Nov 1998

Sorry I am too rushed to look at the script, but what is it actually meant to do?
Thanks,
JP

----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center

They have: 2,390 posts

Joined: Nov 1998

oh thanks Smiling
JP

----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.