Please help: On list box change event open new url in current window

Discussion in 'Javascript' started by Paul, Oct 16, 2003.

  1. Paul

    Paul Guest

    Hi,

    How do I on the change event of a list box open a new url in the
    current window in which the list box resides. I'm not using frames.

    Thanks,

    Paul
    Paul, Oct 16, 2003
    #1
    1. Advertising

  2. (Paul) writes:

    > How do I on the change event of a list box open a new url in the
    > current window in which the list box resides. I'm not using frames.


    I assume you mean a select element, not a "list box".

    <select onchange="location.href=this.options[this.selectedIndex].value">
    <option value="http://www.google.com">Google!</option>
    <option value="http://www.google.com">Google again!</option>
    </select>

    However(!), you should not make a destructive update in an onchange
    handler for a select element. People navigating with the keyboard will
    not be able to reach anything but the first option. It also breaks with
    the expected behavior of a select element: something you change, and
    makes it act more like, e.g., a button: something that makes things
    happen. It is bad for usability to go against the users' expectations.

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Oct 16, 2003
    #2
    1. Advertising

  3. Re: Please help: On list box change event open new url in currentwindow

    Lasse Reichstein Nielsen wrote:
    > (Paul) writes:
    >> How do I on the change event of a list box open a new url in the
    >> current window in which the list box resides. I'm not using frames.

    >
    > I assume you mean a select element, not a "list box".
    >
    > <select onchange="location.href=this.options[this.selectedIndex].value">
    > <option value="http://www.google.com">Google!</option>
    > <option value="http://www.google.com">Google again!</option>
    > </select>
    >
    > However(!), you should not make a destructive update in an onchange
    > handler for a select element. People navigating with the keyboard will
    > not be able to reach anything but the first option. [...]


    Depends. People navigating with the keyboard can use the Alt+$Cursor
    key combination to dropdown the list in some UAs when size="1" is used.
    Then the `onchange' handler fires only when they confirm their selection
    with the Return key.

    In ordinary lists you're right: The onchange handler should not be used
    there.


    PointedEars
    Thomas 'PointedEars' Lahn, Oct 19, 2003
    #3
    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. Gordon
    Replies:
    3
    Views:
    296
    Steven Burn
    Apr 16, 2004
  2. Richard A. Melia

    Open new file in current window

    Richard A. Melia, Apr 16, 2004, in forum: Javascript
    Replies:
    2
    Views:
    110
    Richard A. Melia
    Apr 16, 2004
  3. PC HUA
    Replies:
    2
    Views:
    404
    PC HUA
    May 19, 2004
  4. Replies:
    7
    Views:
    214
    Henry
    Sep 25, 2007
  5. Replies:
    1
    Views:
    231
Loading...

Share This Page