Click to See Complete Forum and Search --> : radio button woes


NewerThanNew
04-25-2003, 01:39 PM
this isn't working:
function clear() {
if (ed1.checked = "true") {
document.f4.ed2.checked = "false";
document.f4.ed3.checked = "false";
}
}

I have 3 radio buttons and the first on ed1 when the user selects it must clear the other two if they are selected, ed2 and ed3 have multiple questions so they are part of a set like so checking ed1 will unselect ed2 and ed3 and selecting ed2 or ed3 will unselect ed1, i'm calling clear from onsubmit, if possible can the function be total contained in the onsubmit call like onSubmit = "javascript:clear(.... If not thats kool.

Jona
04-25-2003, 01:39 PM
function clear() {
if(document.f4.ed1.checked == true) {
document.f4.ed2.checked = false;
document.f4.ed3.checked = false;
}
}

NewerThanNew
04-25-2003, 01:47 PM
it not functioning, when ed1 is selected, ed2 and ed3 remain selected

function clear() {
if(document.f4.ed1.checked == true) {
document.f4.ed2.checked = false;
document.f4.ed3.checked = false;
}
}

</head>
<body>


<input type="radio" value="0" name="ed1" onClick="JavaScript:clear();">

khalidali63
04-25-2003, 01:51 PM
The code should work,My suggestion is check the way your acalling thei clear() function...

or post your code here

Jona
04-25-2003, 01:53 PM
You need onClick="clear()" no "javascript:" part. Also, you've named all of your radios differently. They should have the same name, and you should be using elements[n] where n is the number of the radio element in the form.

NewerThanNew
04-25-2003, 02:07 PM
I'm confused
<html>
<head>

<SCRIPT LANGUAGE="JavaScript"><!--
function clear() {
if(document.f4.ed1.checked == true) {
document.f4.ed2[n].checked = false;
document.f4.ed3[n].checked = false;
}
}
//-->

</SCRIPT>
</head>
<body>

<form>
<p>r1<input type="radio" value="0" name="ed1" onClick="clear()"></p>
<p>r2 option a<input type="radio" name="r2" value="8"></p>
<p>r2 option b<input type="radio" name="r2" value="10"></p>
<p>r3 option a<input type="radio" name="r3" value="8"></p>
<p>r3 option b<input type="radio" name="r3" value="10"></p>
<p><input type="submit" value="Submit"></p>
</form>

</body>
</html>

khalidali63
04-25-2003, 02:11 PM
your form does not have a name attribute

form name="f4" >

will do it

Jona
04-25-2003, 02:15 PM
Khalid, I just tested this, and for some reason I cannot use the document.formname.radio.checked = false; code to uncheck the radio button. I also tried return false; but that didn't work either...

NewerThanNew
04-25-2003, 02:19 PM
sry, my mistake... but it still does not work ? any suggestions?..

<html>
<head>
<SCRIPT LANGUAGE="JavaScript"><!--
function clear() {
if(document.f4.ed1.checked == true) {
document.f4.ed2.checked = false;
document.f4.ed3.checked = false;
}
}
//-->

</SCRIPT>
</head>
<body>

<form name="f4">
<p>r1<input type="radio" value="0" name="ed1" onClick="clear()"></p>
<p>r2 option a<input type="radio" name="r2" value="8"></p>
<p>r2 option b<input type="radio" name="r2" value="10"></p>
<p>r3 option a<input type="radio" name="r3" value="8"></p>
<p>r3 option b<input type="radio" name="r3" value="10"></p>
<p><input type="submit" value="Submit"></p>
</form>

</body>
</html>

khalidali63
04-25-2003, 02:19 PM
I think you overlooked the form name attribute...its not set in the original code..

Jona
04-25-2003, 02:20 PM
No, Khalid, I actually updated it all and even re-renamed the form boxes (because in his HTML the radio buttons are referring to non-existent form elements).

khalidali63
04-25-2003, 02:21 PM
oh crap..the code is wron....just actually took a good look at it..radio buttons are named individually...I should have read the question to begin with...
name all your radio buttons as same....

khalidali63
04-25-2003, 02:26 PM
radio buttons are by default meant to be selected only one in a list,therefore you create a group of radio buttons byusing the same name,in your case all of the radio buttons should be named rd1 or just rd,that will by default inforce one radio button selection at any given time

<form name="f4">
<p>r2 option a<input type="radio" name="r1" value="8"></p>
<p>r2 option b<input type="radio" name="r1" value="10"></p>
<p>r3 option a<input type="radio" name="r1" value="8"></p>
<p>r3 option b<input type="radio" name="r1" value="10"></p>
<p><input type="submit" value="Submit"></p>
</form>

NewerThanNew
04-25-2003, 03:59 PM
Now i'm really confused, i know that radio button by default when you name them the same will only allow only 1 to be selected, but thats not what my situation is, firstly i need to use radio buttons only, and i need 3 sets, if you view this code in your favorite browser you will see 3 sets when you try it: (i need two options for 2nd set (r2), 2 options for the 3rd set (r3) and the first set has one option (r1) that will deselect either 2nd or 3rd set when it is selected and that will be deselected when either 2nd or 3rd set is selected, hope this clears things up.) I really do appreciate the help, thanks so far.

<html>
<head>
</head>
<body>

<form name="f4">
<p>r1<input type="radio" name="ed1" value="0"></p>
<p>r2 option a<input type="radio" name="ed2" value="8"></p>
<p>r2 option b<input type="radio" name="ed2" value="10"></p>
<p>r3 option a<input type="radio" name="ed3" value="8"></p>
<p>r3 option b<input type="radio" name="ed3" value="10"></p>
<p><input type="submit" value="Submit"></p>
</form>

</body>
</html>

NewerThanNew
04-25-2003, 04:51 PM
thanks for you help folks, much appreciate the effort and time.

<html>
<head>
<SCRIPT LANGUAGE="JavaScript"><!--
function setRadios(oCheckbox) {
for (var i=0,j,rad; i<arguments.length; ++i) {
grp = arguments[i], j = 0;
while (rad = grp[j++]) rad.checked = false;
}
}

//-->
</SCRIPT>
</head>
<body>
<form name="f4">
<p>r1<input type="checkbox" value="0" name="ed1" onClick="setRadios(this,ed2,ed3)"></p>
<p>r2 option a<input type="radio" name="ed2" value="8" onclick="if(this.checked)ed1.checked=false"></p>
<p>r2 option b<input type="radio" name="ed2" value="10" onclick="if(this.checked)ed1.checked=false"></p>
<p>r3 option a<input type="radio" name="ed3" value="8" onclick="if(this.checked)ed1.checked=false"></p>
<p>r3 option b<input type="radio" name="ed3" value="10" onclick="if(this.checked)ed1.checked=false"></p>
<p><input type="submit" value="Submit"></p>
</form>

</body>
</html>