Click to See Complete Forum and Search --> : simple text box disable?
NickG21
01-08-2007, 09:35 AM
hey everyone this is the code i have below, all i want is to have my text field disabled on the start of the page and if a checkbox is checked to enable it. i thought this would be easy but has seemed to cause me every problem in the world. good thing i am no good at javascript
<!--
function CheckCheckBox(form1)
{
if (form1.AddVirtualDomain35SetupFee.checked)
form1.PrefListName.enabled = true;
}else{
form1.PrefListName.enabled = false;
}
//-->
onClick="CheckCheckBox(form1)"
konithomimo
01-08-2007, 09:40 AM
in the tag add "disabled" then in your function change enabled=true to disabled=false and enabled=false to disabled=true
NickG21
01-08-2007, 09:48 AM
<!--
function CheckCheckBox(form1, disabled)
{
if (form1.AddVirtualDomain35SetupFee.checked){
form1.PrefListName.disabled = false;
}else{
form1.PrefListName.disabled = true;
}
}
//-->
<input type="checkbox" name="AddVirtualDomain35SetupFee" value="Yes" onClick="CheckCheckBox(form1, disabled)">
i still receive the same errors, in Mozilla CheckCheckBox not defined and in IE: Object Expected on Line 42 where the OnClick is
konithomimo
01-08-2007, 11:29 AM
you can't send it form1 unless form1 is a global JS variable. Instead do:
onClick="CheckCheckBox(this.form, disabled)"
NickG21
01-08-2007, 11:42 AM
thanks, that works well but it doesn't initially have the textbox disables. can i just put in the body onLoad="form1.PrefListName.disabled = true"??
konithomimo
01-10-2007, 11:13 AM
if it is only one textbox then simply add "disabled" to the tag. if you want all textboxes disabled then simply add:
onload="disAll()"
to the body tag, and then insert this function into your header:
function disAll(){
var d = document.forms[0];
var ins = d.getElementsByTagName('input');
for(var i=0;i<ins.length;i++)
{
if(ins[i].type=='text')
ins[i].disabled=true;
}
return;
}
That will disable all textboxes in the first form on the page. Or if you dont want all of them to be disabled then you can specify which ones via their names/IDs or index numbers.
On the other hand, if you mean that you want the textboxes to be hidden, then you change their display.