onclick problem with netscape

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

    onclick problem with netscape

    if i eun this page in IE or netscape it works fine,
    <select name="select" onChange="javas cript:location. href =
    this.options[selectedIndex].value;">
    <option value="[url to load]" >this page </option>
    <option value="[url to load]" >another page</option>
    </select>


    but i would rather have a button for the user to click rather than an
    onchange
    so i modified it to the below - it works in IE but not in netscape, any idea
    why this is

    <form name= "form">
    <select name="select" >
    <option value="[url to load]" >this page </option>
    <option value="[url to load]" >another page</option>
    </select>
    <input type="button" name="but" value="load"
    onclick="javasc ript:location.h ref = select.options. value;">
    </form>


    thanks in advance


  • Martin Honnen

    #2
    Re: onclick problem with netscape



    chris wrote:

    [color=blue]
    > but i would rather have a button for the user to click rather than an
    > onchange
    > so i modified it to the below - it works in IE but not in netscape, any idea
    > why this is
    >
    > <form name= "form">
    > <select name="select" >
    > <option value="[url to load]" >this page </option>
    > <option value="[url to load]" >another page</option>
    > </select>
    > <input type="button" name="but" value="load"
    > onclick="javasc ript:location.h ref = select.options. value;">[/color]

    Use
    <input type="button"
    onclick="window .location.href =
    this.form.eleme nts.select.opti ons[this.form.eleme nts.select.sele ctedIndex].value;"
    to have cross browser code.

    --

    Martin Honnen
    http://JavaScript.FAQT s.com/

    Comment

    • David Dorward

      #3
      Global references to elements (was Re: onclick problem with netscape)

      chris wrote:
      [color=blue]
      > so i modified it to the below - it works in IE but not in netscape, any[/color]
      [color=blue]
      > <input type="button" name="but" value="load"
      > onclick="javasc ript:location.h ref = select.options. value;">[/color]

      Most browsers do not create global variables referencing named elements on
      the page.

      Your entire approach to this problem is fairly poor though, have a read of:
      http://www.cs.tut.fi/~jkorpela/forms/navmenu.html (as you don't want the
      onchange bits, you can just delete that attribute entirely from the example
      code).


      --
      David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
      Home is where the ~/.bashrc is

      Comment

      • chris

        #4
        Re: onclick problem with netscape

        thanks that worked

        "Martin Honnen" <mahotrash@yaho o.de> wrote in message
        news:4128a720$0 $28853$9b4e6d93 @newsread4.arco r-online.net...[color=blue]
        >
        >
        > chris wrote:
        >
        >[color=green]
        > > but i would rather have a button for the user to click rather than an
        > > onchange
        > > so i modified it to the below - it works in IE but not in netscape, any[/color][/color]
        idea[color=blue][color=green]
        > > why this is
        > >
        > > <form name= "form">
        > > <select name="select" >
        > > <option value="[url to load]" >this page </option>
        > > <option value="[url to load]" >another page</option>
        > > </select>
        > > <input type="button" name="but" value="load"
        > > onclick="javasc ript:location.h ref = select.options. value;">[/color]
        >
        > Use
        > <input type="button"
        > onclick="window .location.href =
        >[/color]
        this.form.eleme nts.select.opti ons[this.form.eleme nts.select.sele ctedIndex].v
        alue;"[color=blue]
        > to have cross browser code.
        >
        > --
        >
        > Martin Honnen
        > http://JavaScript.FAQT s.com/[/color]


        Comment

        • Toby Inkster

          #5
          Re: onclick problem with netscape

          chris wrote:
          [color=blue]
          > <form name= "form">
          > <select name="select" >
          > <option value="[url to load]" >this page </option>
          > <option value="[url to load]" >another page</option>
          > </select>
          > <input type="button" name="but" value="load"
          > onclick="javasc ript:location.h ref = select.options. value;">
          > </form>[/color]

          <form>
          <select id="potato">
          <option value="http://example.org/">Example.o rg</option>
          <option value="http://example.com/">Example.c om</option>
          </select>
          <input onclick="locati on.href=documen t.getElementByI d('potato').opt ions[document.getEle mentById('potat o').selectedInd ex].value;">
          </form>

          But this is a *really* bad idea because:

          - it means that people who have Javascript disabled (about 1 in 10) are
          unable to use your navigation system; and

          - search engines don't fill in forms so won't be able to crawl your site.

          A much better way of doing it is:

          <ul>
          <li><a href="http://example.org/">Example.o rg</a></li>
          <li><a href="http://example.com/">Example.c om</a></li>
          </ul>

          --
          Toby A Inkster BSc (Hons) ARCS
          Contact Me ~ http://tobyinkster.co. uk/contact

          Comment

          Working...