By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.