Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable and enable checkboxes 1

Status
Not open for further replies.

novice2004

Programmer
Feb 2, 2004
62
US
Does anybody know about script that disable and enable
checkboxes based on radio choice.

Default is Animal_AllergicYesNo is "No" and
checkboxes for Dogs, Cats, ... are disabled
When client clicks yes - Dogs, Cats, ... get enabled
and client can select checkboxes.


<TR>
<TD class=contactUsFont height=5 width="" align="right">
Are you allergic to any animals?
</TD>

<TD height=5 align="left">

<INPUT type=radio onFocus="promptEntry('')" value=Yes name="Animal_AllergicYesNo">Yes
<INPUT type=radio onFocus="promptEntry('')" value=No name="Animal_AllergicYesNo">No

&nbsp;&nbsp;&nbsp;&nbsp

If yes, which animals?

<INPUT type=checkbox onFocus="promptEntry('')" name="Animal_Allergic1" value="Dogs">Dogs

<INPUT type=checkbox onFocus="promptEntry('')" name="Animal_Allergic2" value="Cats">Cats

<INPUT type=checkbox onFocus="promptEntry('')" name="Animal_Allergic3" value="Birds">Birds

<INPUT type=checkbox onFocus="promptEntry('')" name="Animal_Allergic4" value="Other">Other
</TD>
</TR>
 
You have to use the same name="whatever" in all the inputs. In other words, all the checkBox name="whatever" have to have the same name.

You can also assign the names yourself:
name="whatever[0]"
name="whatever[1]"
name="whatever[2]"
etc. and so forth

JavaScript will automatically convert all the checkBoxes with the same name into an array.

When you check a new checkBox, the current one that's checked will uncheck.

Use a Reset Button to clear all the checkBoxes.

neckbone
 
If you want to have a checkBox checked as default when the page loads:

Write a function in the <head> with a line something like the following. If you want checkBox whatever[0] to be the default:

function checkIt() {
document.myForm.whatever[0].checked=true;
}


call the function with onload="checkIt()" in your body tag and whatever[0] will be checked when the page loads.

good luck,
neckbone



 
Thank you.
I am sorry but I did not explain properly what I want and if it is even possible.

When radio button
Animal_AllergicYesNo
"No" is checked

you can't see checkboxes dogs , cats, ...

If Animal_AllergicYesNo "Yes" is checked
posibility of making a choice for dogs , cats, ... appears
 
Hi novice2004,

Here is a script that will disable the choices. I realize that isn't really your desire.

-----------------
<form name="myform" action="--WEBBOT-SELF--" method="POST">
<!--webbot
bot="SaveResults"
-->&nbsp;
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>
<SCRIPT LANGUAGE=Javascript>

function disable(OnOff) {
var f = myform;
f.allergy_dogs.disabled=OnOff;
f.allergy_cats.disabled=OnOff;
f.allergiy_birds.disabled=OnOff;
f.allergy_other.disabled=OnOff;
f.allergy_other_specify.disabled=OnOff;

}
</SCRIPT>&nbsp;Are you allergic to any animals?
&nbsp;
Yes<INPUT TYPE="Radio" VALUE='ENABLE' onClick=disable(false); name="Allergic">&nbsp;&nbsp;&nbsp;
No <INPUT TYPE="Radio" VALUE='DISABLE' onClick=disable(true); name="Allergic">

&nbsp;
</p>
<p>
&nbsp;If so, what animals?
</p>
<p>
&nbsp;Dogs
<input type="checkbox" name="allergy_dogs" value="Yes">&nbsp;
Cats
<input type="checkbox" name="allergy_cats" value="Yes">&nbsp;
Birds
<input type="checkbox" name="allergiy_birds" value="Yes">&nbsp;&nbsp;
</p>
<p>
&nbsp;Other
<input type="checkbox" name="allergy_other" value="Yes">
If
other,
what
<input type="text" name="allergy_other_specify" size="20">
</p>
<p>
&nbsp;


<input value="Submit"type="submit">
<input value="Reset"type="reset">
</p>
</form>
-----------------

Here is a link that might give you more along the lines of your original request.


Hope I have been of some help,
Micheal

FrontPage Form Tutorials & Form Script Examples
 
My apologies, I left the FP trash in the beginning <Form> tag. Sorry!

action="--WEBBOT-SELF--" method="POST">
<!--webbot
bot="SaveResults"
-->

Hope I have been of some help,
Micheal

FrontPage Form Tutorials & Form Script Examples
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top