tags:

views:

323

answers:

4

Every <option> in an HTML <select> will have external URL and should open in new a window. If it's possible to make in CSS and HTML only then good, if not possible without JavaScript then it should be unobtrusive.

A: 

The target attribute defines where the linked document will be opened.

<a href="http://stackoverflow.com" target="_blank">Stackoverflow</a>
The MYYN
can we give <a> href to <option>item1</option>
metal-gear-solid
That's a link, not a jump menu.
David Dorward
+2  A: 

You can't open links from <select> elements without Javascript. The way to open a new Window with Javascript is like this:

window.open("http://example.com");

To attach to the <select> element, try this:

$('#selectId').change( function() {
    window.open( $(this).val() );
}

Assuming the URL is set in the value attribute of each <option> element.

DisgruntledGoat
this assumes jquery or a similar library is used, it is not pure javascript.
Adriano Varoli Piazza
@DisgruntledGoat, did you edit the OP and added the jquery Tag ?!?
Gaby
@Gaby: How about checking the edit before asking silly questions? :p
DisgruntledGoat
@DisgruntledGoat, i knew it was far fetched (from the first comment).. Also i did not know i could see the edits ... I apologize.. *blush*
Gaby
+4  A: 

The “jump menu” is a discredited navigational device from many years ago that should not be brought back.

Auto-navigate-on-change <select> menus are unsuitable for navigation because:

  1. keyboard users will be firing a change event every time they move the selection, making it impossible for them to use the control;

  2. non-JavaScript agents (including search engines) won't be able to see or follow the links;

  3. form values are retained over page back/forward navigations, making the select show the wrong value after a navigation, making it impossible to select the same option again;

  4. users can't use their browser's normal navigational tools like middle-click, ‘open in new tab’ or ‘bookmark link’.

Therefore the ‘best’ way to make a jump menu is not to. If you want something that behaves similarly but doesn't have these disadvantages, go for a <div> that's hidden and re-popped-up by JavaScript, containing plain <a> links pointed at the pages they go to. You can style it to look like a dropdown if you really want, and you can make them open new windows when left-clicked if you must (I wish you wouldn't, though).

bobince
but use of scripted <div> is schematically correct? and if we will use <div> then what will happen if css and js is disabled
metal-gear-solid
+1 for detailed and great answer
Gaby
If CSS is disabled you get a simple list of links, which is about the best you can hope for. To make it still usable without JS, you have the div visible in the normal page, then use script to hide it until it's toggled open.
bobince
ok then i think this will be a good option http://stackoverflow.com/questions/1897129/how-to-convert-unordered-list-into-nicely-styled-select-dropdown-using-jquery
metal-gear-solid
I agree with the general principle, but: “Keyboard users will be firing a change event every time they move the selection, making it impossible for them to use the control.” Is that true? I thought the `onchange` event only fired once you’d actually chosen an option in a `select` field.
Paul D. Waite
It's browser-dependent. Currently IE and Opera fire `onchange` on every keyboard up/down, whilst Firefox and Webkit delay the `onchange` until `onblur`. (Which isn't great either: you choose a page, then nothing happens until you happen to click or tab to somewhere else, causing the field to unfocus.)
bobince
i realized if <select> is not good then why we need to make it from <div> and <a> we can make it from regular <ul> <li> <a>
metal-gear-solid
A: 

I think Unobtrusive page changer by Chris Coyier is the best method.

Tae