468,316 Members | 2,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Disabling a text field by clicking an option (works with Firefox but not with IE6)

This following HTML page works fine in Firefox 1.5 but not in IE6. Help
is appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<meta http-equiv="content-script-type" content="text/javascript">
<title>Just a test</title>
</head>
<body>

<script language="JavaScript">
<!--

function enableTextField() {
document.testForm.textField.disabled = false;
}

function disableTextField() {
document.testForm.textField.disabled = true;
}

//-->
</script>

<form action="test.html" method="post" name="testForm"
enctype="text/plain">
<select name="sel">
<option name="enable" onclick="enableTextField()">Enable text field
<option name="disable" onclick="disableTextField()">Disable text field
</select>

<input type="text" name="textField" value="" size="40"/>

</form>

Best regards,

Mark

Dec 28 '05 #1
1 7837
Mark Noten wrote:
This following HTML page works fine in Firefox 1.5 but not in IE6. Help
is appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<meta http-equiv="content-script-type" content="text/javascript">
<title>Just a test</title>
</head>
<body>

<script language="JavaScript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

<!--
HTML comment delimiters inside script elements serve no useful purpose
and are potentially harmful.


function enableTextField() {
document.testForm.textField.disabled = false;
}

function disableTextField() {
document.testForm.textField.disabled = true;
}

//-->
</script>

<form action="test.html" method="post" name="testForm"
enctype="text/plain">
<select name="sel">
<option name="enable" onclick="enableTextField()">Enable text field
<option name="disable" onclick="disableTextField()">Disable text field
Putting event handlers on option elements creates a number of
usability issues (you've just discovered one, there are others). In
general, if you have a choice of two options, use a checkbox. Then
you can do something like:

<input type="checkbox"
onclick="toggleTextField(this, this.form.textField);"Disable text field?

And the function can be:

function toggleTextField( c, x )
{
if ( 'boolean' == typeof x.disabled ){
x.disabled = c.checked;
}
}

[...]
--
Rob
Dec 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Applebrown | last post: by
4 posts views Thread by Fluffy Convict | last post: by
9 posts views Thread by lkrubner | last post: by
4 posts views Thread by ioneabu | last post: by
1 post views Thread by dominpe | last post: by
3 posts views Thread by dugald.morrow | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.