/    Sign up×
Community /Pin to ProfileBookmark

changing field attributes based on field selections

I have a drop down with two values, yes and no. We’ll call that field field_a. If no is selected in field_a, I want to change the attributes of field_b to readOnly and change the background color to grey. How do I do it??? Thanks in advance!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvMay 24.2004 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript">
onload = function() { document.forms[0]['field'].disabled = true; }
</script>
</head>
<body>
<form action="#">
<div>
<select onchange="field.disabled=this.value!='yes'">
<option value="">< select an option ></option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<input type="text" name="field">
</div>
</form>
</body>
</html>
Copy linkTweet thisAlerts:
@skatehackauthorMay 24.2004 — It almost works... ? I neglected to mention that the field in question is a select field. It works to disable the select field, but it does not clear the field on the selection of no, and if you select yes, it does not enable the field(it remains disabled). Thanks again for the help. I am starting to understand JavaScript more and more thanks to you all.




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>

<title>untitled</title>

<meta http-equiv="content-type" content="text/html; charset=utf-8">

<script language="JavaScript1.2">

onload = function() { document.forms[0]['field'].disabled = true; }

</script>

</head>

<body>

<form action="blah" name="gojoe">

<div>

<select onchange="field.disabled=this.value!='yes'">

<option value="">&lt; select an option &gt;</option>

<option value="yes">Yes</option>

<option value="no">No</option>

</select>

<input type="text" name="field">

<input type="text" name="field_b">

<input type="text" name="field_c">

</div>

</form>

<form action="blah" name="cobra">

<div>

<select onchange="field.disabled=this.value!='yes'">

<option value="">&lt; select an option &gt;</option>

<option value="yes">Yes</option>

<option value="no">No</option>

</select>

<select name="field">

<option value="">&lt; select an option &gt;</option>

<option value="1">1</option>

<option value="2">2</option>

</select>

<input type="text" name="field_b">

<input type="text" name="field_c">

</div>

</form>

</body>

</html>
×

Success!

Help @skatehack 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.19,
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,
)...