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

Discussion in 'Javascript' started by Mark Noten, Dec 28, 2005.

  1. Mark Noten

    Mark Noten Guest

    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
     
    Mark Noten, Dec 28, 2005
    #1
    1. Advertising

  2. Mark Noten

    RobG Guest

    Re: Disabling a text field by clicking an option (works with Firefoxbut not with IE6)

    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
     
    RobG, Dec 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nospam
    Replies:
    4
    Views:
    392
    Nospam
    Jan 27, 2007
  2. Dennis McCarthy

    CheckBoxField works in Firefox but not in IE6

    Dennis McCarthy, Jan 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    115
    Dennis McCarthy
    Jan 25, 2007
  3. David Springthorpe

    Works OK In IE6 But Not In Mozilla Firefox 0.9.2

    David Springthorpe, Aug 22, 2004, in forum: Javascript
    Replies:
    1
    Views:
    94
    Michael Winter
    Aug 22, 2004
  4. DamonChong
    Replies:
    4
    Views:
    95
    Damon Chong
    Dec 29, 2005
  5. Steve Wright

    AJAX works in IE6 but not IE7 or Firefox

    Steve Wright, Mar 13, 2007, in forum: Javascript
    Replies:
    5
    Views:
    168
    Bart Lateur
    Mar 15, 2007
Loading...

Share This Page