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

P

Paul

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
 
L

Lasse Reichstein Nielsen

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
 
T

Thomas 'PointedEars' Lahn

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

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top