Jump to content

Disabling a field based on radio button selection.


iPixel

Recommended Posts

Am i doing something wrong?

 

2 Radio Buttons...

 

<input type="radio" name="form_status" id="form_status" value="Active" onchange="ETDF(this)" /> Active
<input type="radio" name="form_status" id="form_status" value="InActive" onchange="ETDF(this)" /> InActive

 

So if "Active" is selected... the field form_termdate has to be disabled, otherwise if InActive is selected the form_termdate field (textbox) has to be enabled.

 

my JS.

 

<script type="text/javascript">
if(document.getElementById("form_status") == "Active")
{
	document.getElementByID("form_termdate").disabled = true;
}

function ETDF(action) // Enable Terminated Date Field
{
	if(action == "Active")
		{
			document.getElementByID("form_termdate").disabled = true;
		}
	else if(action == "InActive")
		{
			document.getElementByID("form_termdate").disabled = false;
		}
}
</script>

 

Thanks for the help!

you're passing the function an object (the radio button element), but you can't compare the object directly to the value you're expecting. you have to use the value property:

 

if(action.value == "Active")

 

give that a whirl.

okay.... are you getting any error messages? have you checked the javascript error console in firefox? it could be that it's tripping on the first if() as well, where you check the object itself against a value, rather than the object's value property.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.