Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.open and IE 1

Status
Not open for further replies.

MrTBC

Technical User
Nov 19, 2003
610
US
Hi.
I'm using a small piece of Javascript to open a URL in a new window when a user selects a value in a combobox:

Code:
<head>
<script type="text/javascript">
function urlopen(target)
  {
  window.open(target)
  }
</script>
</head>

and then:

Code:
<body>
<form name="test"><select name="test"><option VALUE="1" onclick="urlopen('[URL unfurl="true"]http://www.google.com')">Google</option><option[/URL] value="2" onclick="urlopen('[URL unfurl="true"]http://www.yahoo.com')">Yahoo</option>"></select></form>[/URL]
</body>

This is working fine in Firefox and Safari, but does nothing in IE. Any ideas please guys?

Thanks very much
 
Hi

Such thing usually is done on the [tt]select[/tt]'s [tt]onchange[/tt] event. Why not do it like this ?
HTML:
<form>
<select onchange="if(this.selectedIndex)urlopen(this.options[this.selectedIndex].value)">
<option>-- link --</option>
<option value="[URL unfurl="true"]http://google.com/">Google</option>[/URL]
<option value="[URL unfurl="true"]http://yahoo.com/">Yahoo</option>[/URL]
</select>
</form>
The JavaScript [tt]function[/tt] is the same.

Feherke.
 
That works perfectly. Thanks so much Feherke.
 
Is there any way that this script can be modified so that the first option can have a URL please? I'd prefer not to have an entry like <option>-- link --</option> if possible.
 
Hi

You must change the selected item to fire the [tt]onchange[/tt] event. If the first item is also a reference, you could reach it only in two steps : first selecting any other undesired item, then selecting the first one.

Anyway, to make it call urlopen() for the first item too, is enough to remove the [tt]if[/tt] statement :
Code:
<select onchange="urlopen(this.options[this.selectedIndex].value)">

Feherke.
 
OK thanks very much. Looks like I may need another solution then.
 
It doesn't need to be a select, but it does need the default option to be a member of the list.

The annoying thing is that the original script I posted works perfectly in both Firefox and Safari. It's IE that's the problem (as usual). Maybe I could add a small button to the right of the select as an alternative way to fire the script (for IE users).

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top