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

M

Mark Noten

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
 
R

RobG

Mark said:
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:


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;
}
}



[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top