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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable certain boxes 1

Status
Not open for further replies.

Rowse

Technical User
Dec 20, 2002
62
0
0
GB
I want to be able to check a box and have certain text boxes come available, then check a different box and them to not be available, is this possible?

I.e. check box a enables text box 3
check box b enables text box 4 & disables 3
 
you just need a function for each check box, set onClick="doCheck3()" in the cb declaration

then in the function:

document.formName.checkName.enabled="true"; -Greg :-Q

flaga.gif
 
first check for the checked condition
if(document.formname.checkboxname.checked = true) {

now that you have that you can disable things
document.formname.textboxname.disabled = true or false ---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
I've used the code:
<script language=&quot;javascript&quot;>
if (document.Relationship.WholeRel.checked=true)
{document.relationship.groupstat.disabled=false}
</script>

However, i get the following error:
document.Relationship.wholerel is null or not an object.

My form is called Relationship
Checkbox is called WholeRel
Dropdown is called GroupStat

Where am I going wrong?
 
I thought a single '=' meant assignment, ie x=y ?
try double '==', ie:

if (document.Relationship.WholeRel.checked==true)

worth a go...


Joe


 
in the code you posted your caps are inconsistent. Javascript needs the elements to be referenced exactly how they are named, its case sensitive. So you might need to check that the checkbox input is WholeRel and not wholerel...

The following works fine for example:

<HTML>
<HEAD>
<script language=&quot;javascript&quot;>
function testCheck() {
if (document.Relationship.WholeRel.checked=true)
alert(&quot;works&quot;);
}
</script>
</HEAD>
<BODY>
<FORM name=&quot;Relationship&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;WholeRel&quot; checked></INPUT>
<INPUT type=&quot;button&quot; value=&quot;test&quot; onclick=&quot;testCheck()&quot;></INPUT>
</FORM>
</BODY>
</HTML>


Joe.
 
I've modified the script so as when the checkbox is un-ticked the submit button is greyed out, however it still errors, any more ideas?



<script language=&quot;javascript&quot;>function testCheck()
{
if (document.Relationship.WholeRel.checked=true)
(document.Relationship.test.Disabled=true);}</script>


</head>

<body>
<FORM name=&quot;Relationship&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;WholeRel&quot; onclick=&quot;testCheck()&quot; checked></INPUT>
<INPUT type=&quot;button&quot; value=&quot;test&quot;></INPUT></FORM></BODY></HTML>
 
try this lot :)

<HTML>
<HEAD>
<script language=&quot;javascript&quot;>
function testCheck() {

if (document.Relationship.WholeRel.checked==true) {
document.Relationship.testselect.disabled=true;
} else {
document.Relationship.testselect.disabled=false;
}

}
</script>
</HEAD>
<BODY>
<FORM name=&quot;Relationship&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;WholeRel&quot; onClick=&quot;testCheck()&quot;></INPUT>

<select name=&quot;testselect&quot;><option value=&quot;1&quot;>1 line</option><option value=&quot;2&quot;>2 line</option></select>
</FORM>
</BODY>
</HTML>
 
Here's the code that works, but it only allows the tick one way:

<script language=&quot;javascript&quot;>function testCheck()
{
if (document.Relationship.WholeRel.checked=true)
(document.Relationship.button.disabled=false);}


</script>


</head>

<body>
<FORM name=&quot;Relationship&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;WholeRel&quot; onclick=&quot;testCheck()&quot;></INPUT>
<INPUT type=&quot;button&quot; value=&quot;test&quot; name=&quot;button&quot; disabled></INPUT></FORM></BODY></HTML>
 
the answer is in the code I've just posted, you need the opposite state...

Joe.
 
Thanks for that, i hadnt refreshed my screen so didn't see it
 
Ok, how can I do it for more than 1 drop down box? so that about 4 drop downs get enabled or disabled for the 1 tick box
 
the following gets ALL the selects from the form. scrolls through and sets disabled according to the checkbox:


<HTML>
<HEAD>
<script language=&quot;javascript&quot;>
function testCheck() {

var aSelects,vLength;
aSelects=document.Relationship.getElementsByTagName(&quot;SELECT&quot;);
vArrLeng=aSelects.length;
for(var i=0;i<vArrLeng;i++)
{
if (document.Relationship.WholeRel.checked==true) {
document.Relationship.getElementsByTagName(&quot;SELECT&quot;).item(i).disabled=true;
}
else
{
document.Relationship.getElementsByTagName(&quot;SELECT&quot;).item(i).disabled=false;
}
}


}
</script>
</HEAD>
<BODY>
<FORM name=&quot;Relationship&quot;>
<INPUT type=&quot;checkbox&quot; name=&quot;WholeRel&quot; onClick=&quot;testCheck()&quot;></INPUT>

<select name=&quot;testselect1&quot;><option value=&quot;1&quot;>1 line</option><option value=&quot;2&quot;>2 line</option></select>
<select name=&quot;testselect2&quot;><option value=&quot;1&quot;>1 line</option><option value=&quot;2&quot;>2 line</option></select>
<select name=&quot;testselect3&quot;><option value=&quot;1&quot;>1 line</option><option value=&quot;2&quot;>2 line</option></select>
<select name=&quot;testselect4&quot;><option value=&quot;1&quot;>1 line</option><option value=&quot;2&quot;>2 line</option></select>
<select name=&quot;testselect5&quot;><option value=&quot;1&quot;>1 line</option><option value=&quot;2&quot;>2 line</option></select>
</FORM>
</BODY>
</HTML>
 
joezapp
just for information purposes, when checking for a booean value it is = not ==

watch for inconsistencies as you have shown in the code above with both = and == checking for the value. This can acause errors with in different browsers as different browsers will interprute the code in different ways ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
fair enough and thanks for the confirmation. just me being lazy and copying and pasting.

you learn someting new every day and all that :)

Joe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top