Click to See Complete Forum and Search --> : disable and enable an element if another is selected
Jessica Nieves
February 26th, 2003, 03:02 PM
hi everyone!!
I need to enable a set of radio buttons and text fields if an option of a form is selected and disable them if the user do not select the option. The objective is to let the user fill this radios and text fields only if the checked a specified radio button.
I already know how to disable it. I used:
<input type="text" value="122" name="option2" onfocus="option2.blur()">
my problem is that I dont know how to "unblur" the element once the user clicks the radio button. :rolleyes:
Any soon reply will be hiiiiiighly appreciated!! :D
Thanks a lot!!
nategrover
February 26th, 2003, 05:54 PM
Once the user clicks on the radio button that tells you to enable all the other elements, you need to call a function that will know which elements now need to be enabled, and set the elements' onfocus property to null. Note that the onfocus is all lower case when setting it via javascript.
Nate Grover
antares686
February 27th, 2003, 04:42 AM
If you are wanting to disable input items in a form you have to set the disabled flag to true (disabled) or false (enabled). This is kind of backwards from most programming languages.
Also, to reference a set of radio buttons with the same name to set their disabled flag you treat them as a 0 based array. So item 1 is 0 item 2 is 1 and so on.
The following example shows using a checkbox to swap the dsiabled element from the text box to the radio buttons.
Note: the code does not clear the data during the disableing but that can be done.
<SCRIPT LANGUAGE=JAVASCRIPT>
function DisableOpts()
{
if (frmTest.ckDisable.checked)
{
frmTest.rdOpt(0).disabled = true;
frmTest.rdOpt(1).disabled = true;
frmTest.rdOpt(2).disabled = true;
frmTest.txtOpt.disabled = false;
}
else
{
frmTest.rdOpt(0).disabled = false;
frmTest.rdOpt(1).disabled = false;
frmTest.rdOpt(2).disabled = false;
frmTest.txtOpt.disabled = true;
}
}
</SCRIPT>
<form name=frmTest>
<input type=radio name=rdOpt>Test1
<input type=radio name=rdOpt>Test2
<input type=radio name=rdOpt>Test3
<BR>
<input type=test name=txtOpt value='Test4' disabled>
<BR><BR>
<input type=checkbox name=ckDisable OnClick="DisableOpts()">Check to swap
</form>
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.