/    Sign up×
Community /Pin to ProfileBookmark

Disable Form Elements on Check

I searched around and found something similar to what i want to do [URL=http://forums.webdeveloper.com/showthread.php?s=&threadid=23622&highlight=disable+form+object]here[/URL]… and i tried to change it to what im looking for but i dont know enough java… heres all i want to do, i have two single line text fields, i just want them to be disabled when a box is unchecked, and enabled when a box is checked, any help would be much appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@oleragFeb 28.2004 — [code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Sample</title>
<script type="text/javascript">
<!--
function execute(form) {
if (form.cb1.checked) {
form.field1.disabled = false;
form.field2.disabled = false;
}
else {
form.field1.disabled = true;
form.field2.disabled = true;

}
}
-->
</script>

<div style="text-align: center;">
<strong>Sample</strong>
</div>

<form action="#">
<p>
Enter 1: <input type="text" name="field1" size="20" /><br>
Enter 2: <input type="text" name="field2" size="20" />
</p>

<p style="text-align: center;">
<input type="checkbox" name="cb1" value="Y" onChange="execute(this.form)" /> Control
</p>
</form>

<script type="text/javascript">
execute(document.forms[0]);
</script>[/code]
×

Success!

Help @lahmayes 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 4.28,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...