Click to See Complete Forum and Search --> : disable some input on a form


steph
10-17-2003, 02:21 PM
I am trying to create a function using javascript that disables and enables parts to a form. Here is the code:

<script language="javascript">
<!--

function disable(){
document.forms[1].StartDate.disabled=false;
document.forms[1].TerminationDate.disabled=true;
document.forms[1].StartDate.value="";
document.forms[1].TerminationDate.value="";
var announce= document.getElementById("announce");
announce.style.color = "#cccccc";
}

function enable(){
document.forms[1].StartDate.disabled=true;
document.forms[1].TerminationDate.disabled=false;
var announce= document.getElementById("announce");
announce.style.color = "#000000";
}

//-->
</script>

the error that I am getting is that the StartDate is Null or not an object, and I am not sure what to do. Hopefully this is enough information, Thanks in advance.

sharapov
10-17-2003, 02:41 PM
Try this:



<html>

<head>
<script>
var oToggle=0;

function disable(){

if(oToggle == '0'){

document.oForm.StartDate.disabled=true;
oToggle=1;
}else{
document.oForm.StartDate.disabled=false;
oToggle=0;
}
}


</script>
<title></title>
</head>

<body>
<form name="oForm">
<input type=text name=StartDate>
</form>
<button onclick="disable()">Disable/Enable</button>
</body>
</html>

Jenny
10-17-2003, 02:41 PM
change forms[1] to forms[0], it will work.

Jenny