problems with IE and select/option value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve cole

    problems with IE and select/option value

    Hi All

    No doubt I am doing something stupid since i am new to javascript

    I have a problem with the following code, when run on IE6 the value for
    opt_sel is null but on Mozilla or konqueror the value is the option
    selected (as expected). I have tried several books on the matter(and
    google), but they seem to indicate that what i am trying to do should
    work... Very annoying!
    I have made the script as simple as possible to illustrate my problem.
    please help, this is driving me crazy!!!!

    <html>
    <head>

    <script language=JavaSc ript type=text/javascript>
    function check_form(){
    alert (document.form1 .opt_sel.value)
    }
    </script>
    </head>

    <body>
    <form name=form1 id=form1>
    <select name="opt_sel" id="opt_sel">
    <option selected>opt1</option>
    <option>opt 2</option>
    <option>opt 3</option>
    </select>

    <input name="submit" value="submit" type="submit" onclick=check_f orm()>

    </form>
    </body>
    </html>


    Thanks

    Steve
  • Ivo

    #2
    Re: problems with IE and select/option value

    "steve cole" wrote[color=blue]
    > I have a problem with the following code, when run on IE6 the value for
    > opt_sel is null but on Mozilla or konqueror the value is the option
    > selected (as expected).[/color]
    <snip>[color=blue]
    > <script language=JavaSc ript type=text/javascript>[/color]

    Don't use the language attribute, no browser needs it. Put quotes around the
    type value. It is good habit to always put values in quotes, when there are
    weird characters (such as the slash), they are required.
    [color=blue]
    > function check_form(){
    > alert (document.form1 .opt_sel.value)[/color]

    alert (document.form1 .opt_sel[document.form1. opt_sel.selecte dIndex].text)
    The options in your code don't have values, so I alert the text.
    HTH
    Ivo
    [color=blue]
    > }
    > </script>
    > </head>
    >
    > <body>
    > <form name=form1 id=form1>
    > <select name="opt_sel" id="opt_sel">
    > <option selected>opt1</option>
    > <option>opt 2</option>
    > <option>opt 3</option>
    > </select>
    >
    > <input name="submit" value="submit" type="submit" onclick=check_f orm()>
    >
    > </form>
    > </body>
    > </html>
    >
    >
    > Thanks
    >
    > Steve[/color]


    Comment

    • steve cole

      #3
      Re: problems with IE and select/option value

      On Thu, 01 Jul 2004 23:31:21 +0200, Ivo wrote:
      [color=blue][color=green]
      >> function check_form(){
      >> alert (document.form1 .opt_sel.value)[/color]
      >
      > alert (document.form1 .opt_sel[document.form1. opt_sel.selecte dIndex].text)
      > The options in your code don't have values, so I alert the text.
      > HTH
      > Ivo
      >[/color]
      Thanks
      That did the job.
      Steve

      Comment

      Working...