Click to See Complete Forum and Search --> : Radio Buttons Question


kittyblueboots
09-23-2003, 09:04 PM
I have a form with radio buttons which lists different ways for a person to be contacted. Once a radio button is clicked, it checks to see whether the information exists. If it doesn't it returns a message requesting the information. Now this is all fine.

My problem: How can I force the radio button to be 'un-selected' if there is no information for that contact?

Heres the section of code affected:

function CheckContact(contact) //contact is the name of the
//radio buttons
{
for (var index = 0; index < contact.length; index++)
{
if (contact[index].checked)
{
var answer = contact[index];
break;
}
}
if (answer.value == "email") //only testing the email
{ //for now
email = document.getElementById("email");
if (email.value == "") //if empty
{
alert ("You have not entered an email address for us\n" +
"to contact you by.");
email.focus();

//something belongs here to uncheck my radio
//button

return false;
}
}
if (answer == "postal")
{
alert ("postal");
}
if (answer == "phone")
{
alert ("phone");
}

}

I would really appreciate the help.

JavaJavaJavaJavaJavaJavaJavaJavaJavaJavaJavaJavaJavaJava

luv, Kitty

pyro
09-23-2003, 10:59 PM
You can use something like this to uncheck radio buttons. This will uncheck all of the radio buttons in the form that you specify. If you only want to do a few of them, you'll have to modify it a bit...

<script type="text/javascript">
function uncheck() {
for (i=0; i<document.formname.elements.length; i++) {
if (document.formname.elements[i].type == "radio") {
document.formname.elements[i].checked = "";
}
}
}
</script>
</head>
<body>
<form name="formname">
<p><input type="radio" name="rad1">
<input type="radio" name="rad2">
<input type="radio" name="rad3"><br>
<button type="button" onclick="uncheck();">Uncheck</button></p>
</form>

kittyblueboots
09-24-2003, 08:37 PM
Thanks Pyro,

That code worked quite well!

Luv Kitty

pyro
09-24-2003, 09:11 PM
You are very welcome. I was happy to help... :)