Click to See Complete Forum and Search --> : Dropdown and textbox problem


bruticus
02-10-2004, 01:54 PM
i've been trying to this all day but with no avail....

How do you enable a textbox using a dropdown menu?

fredmv
02-10-2004, 02:07 PM
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="">&lt; select an option &gt;</option>
<option value="false">enabled</option>
<option value="true">disabled</option>
</select>
<input type="text" disabled="disabled" />
</div>
</form>
</body>
</html>

bruticus
02-10-2004, 02:19 PM
wow that was fast. thank you very much :D

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


<select>
<option value="item1"> Item1 </option>
<option value="others"> Others </option>
</select>


so the textbox is only enabled when i select "Others".

fredmv
02-10-2004, 02:22 PM
You're welcome; it'd be done like this:<!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 == 'item1' ? true : false;">
<option value="">&lt; select an option &gt;</option>
<option value="item1">Item1</option>
<option value="others">Others</option>
</select>
<input type="text" disabled="disabled" />
</div>
</form>
</body>
</html>

bruticus
02-10-2004, 02:30 PM
thanks again for the quick response....:D

bruticus
02-10-2004, 04:14 PM
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?:(

96turnerri
02-10-2004, 04:28 PM
yeah you host may have disabled js


<!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>


see whether that works

bruticus
02-10-2004, 04:32 PM
yup it works fine. I suspect it's the


disabled="disabled"


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