mudface061200
asked on
2 radio buttons and simple function
<script language="javascript">
function enabled(chosen)
{
alert(chosen);
//This function takes the option that is chosen and disables the other two
if (chosen == "meter")
{
document.TheForm.region.se lectedInde x = 0;
document.TheForm.district. selectedIn dex = 0;
document.TheForm.usage.che cked = false;
}
else if(chosen == "district")
{
document.TheForm.meter.sel ectedIndex = 0;
document.TheForm.region.se lectedInde x = 0;
}
else if(chosen == "region")
{
document.TheForm.meter.sel ectedIndex = 0;
document.TheForm.district. selectedIn dex = 0;
}
else
{
document.TheForm.meter.sel ectedIndex = 0;
}
}
</script>
<input type="radio" name="usage" value="van" onClick="enabled(document. TheForm.us age.value) ;">
<input type="radio" name="usage" value="total" onClick="enabled(document. TheForm.us age.value) ;">
Whenever the radio buttons are clicked on, my alert statment says chosen is undefined. I am wanting to set both radio buttons to unchecked if the meter drop box is selected. Any thoughts?
-m
function enabled(chosen)
{
alert(chosen);
//This function takes the option that is chosen and disables the other two
if (chosen == "meter")
{
document.TheForm.region.se
document.TheForm.district.
document.TheForm.usage.che
}
else if(chosen == "district")
{
document.TheForm.meter.sel
document.TheForm.region.se
}
else if(chosen == "region")
{
document.TheForm.meter.sel
document.TheForm.district.
}
else
{
document.TheForm.meter.sel
}
}
</script>
<input type="radio" name="usage" value="van" onClick="enabled(document.
<input type="radio" name="usage" value="total" onClick="enabled(document.
Whenever the radio buttons are clicked on, my alert statment says chosen is undefined. I am wanting to set both radio buttons to unchecked if the meter drop box is selected. Any thoughts?
-m
ASKER
Wow, there isn't a cleaner way to clear 2 radio buttons if a drop down menu is selected?
-m
-m
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! I don't know why I didn't think of that earlier.
-m
-m
You need to use the object hierachy to pass the value of the selected radio button, like this:
<form name=TheForm>
<input type="radio" name="usage" value="van" onClick="enabled(this.valu e);">
<input type="radio" name="usage" value="total" onClick="enabled(this.valu e);">
</form>
I'm not sure what it is you exactly are trying to do.
If you you post the whole code including the drop down menus and explain it a little better, i'll mix up a working sollution for you :)
<form name=TheForm>
<input type="radio" name="usage" value="van" onClick="enabled(this.valu
<input type="radio" name="usage" value="total" onClick="enabled(this.valu
</form>
I'm not sure what it is you exactly are trying to do.
If you you post the whole code including the drop down menus and explain it a little better, i'll mix up a working sollution for you :)
ASKER
psogaa,
Once inside my function, how would I reference those radio buttons? I.E. How can I tell them to be unselected?
Once inside my function, how would I reference those radio buttons? I.E. How can I tell them to be unselected?
ASKER
Nevermind. I now understand radio buttons are handled as arrays..
function getselectedbutton(buttongr
{
for (var i=0; i <buttongroup.length;i++)
{
if (buttongroup[i].checked)
{
return buttongroup[i].value;
break;
}
}
alert("you must select a value from the radio buttons");
return(false);
}
So, you should be able to do the following:
Add this function to your script
Change the onclick to enable(document.TheForm.us
Add the following to your function
newvariablename= getselectedbutton(chosen)
I haven't checked the rest of it, so there may some other minor changes, but that should basically do it.
Ethan