/    Sign up×
Community /Pin to ProfileBookmark

disable some input on a form

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.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@sharapovOct 17.2003 — Try this:

<i>
</i>
&lt;html&gt;

&lt;head&gt;
&lt;script&gt;
var oToggle=0;

function disable(){

if(oToggle == '0'){

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


&lt;/script&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name="oForm"&gt;
&lt;input type=text name=StartDate&gt;
&lt;/form&gt;
&lt;button onclick="disable()"&gt;Disable/Enable&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;

Copy linkTweet thisAlerts:
@JennyOct 17.2003 — change forms[1] to forms[0], it will work.

Jenny
×

Success!

Help @steph spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...