/    Sign up×
Community /Pin to ProfileBookmark

Dropdown and textbox problem

i’ve been trying to this all day but with no avail….

How do you enable a textbox using a dropdown menu?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@fredmvFeb 10.2004 — Welcome to the forums.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<body>
<form action="#">
<div>
<select onchange="elements[1].disabled = options[selectedIndex].value == 'false' ? false : true">
<option value="">< select an option ></option>
<option value="false">enabled</option>
<option value="true">disabled</option>
</select>
<input type="text" disabled="disabled" />
</div>
</form>
</body>
</html>
Copy linkTweet thisAlerts:
@bruticusauthorFeb 10.2004 — wow that was fast. thank you very much ?

also i was wondering if it could be possible to use an IF statement on this for example

[code=php]
<select>
<option value="item1"> Item1 </option>
<option value="others"> Others </option>
</select>
[/code]


so the textbox is only enabled when i select "Others".
Copy linkTweet thisAlerts:
@fredmvFeb 10.2004 — You're welcome; it'd be done like this:&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
&lt;head&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="#"&gt;
&lt;div&gt;
&lt;select onchange="elements[1].disabled = options[selectedIndex].value == 'item1' ? true : false;"&gt;
&lt;option value=""&gt;&amp;lt; select an option &amp;gt;&lt;/option&gt;
&lt;option value="item1"&gt;Item1&lt;/option&gt;
&lt;option value="others"&gt;Others&lt;/option&gt;
&lt;/select&gt;
&lt;input type="text" disabled="disabled" /&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@bruticusauthorFeb 10.2004 — thanks again for the quick response....?
Copy linkTweet thisAlerts:
@bruticusauthorFeb 10.2004 — the code works fine when i tested it on a local browser but when i used it on IIS or uploaded it the script doesn't seems to function. Any ideas??
Copy linkTweet thisAlerts:
@96turnerriFeb 10.2004 — yeah you host may have disabled js

[code=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<body>
<script type="text/javascript" />
document.write("Hello!");
</script>
</body>
</html>
[/code]


see whether that works
Copy linkTweet thisAlerts:
@bruticusauthorFeb 10.2004 — yup it works fine. I suspect it's the

[code=php]
disabled="disabled"
[/code]


code on the text box that's doing it...but then again maybe i'm wrong....
×

Success!

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