# HTML onChange, need help.



## zyntrax (May 8, 2007)

I need help with my code, when i select ex. Tillverkare on the menu it opens up a new window i dont want it to open a new window when i select certain things, how do i do? My code looks like this:

<a href="Forms.HTML:Submitbutton.1"><span
style='color:black;text-decoration:none;text-underline:none'>
<select name="select" onChange="window.open(options[selectedIndex].value)">
<option selected>Tiilverkare
<option>---
<option value="http://www.3com.se/">3com
<option value="http://www.acercomputer.se/">Acer
<option value="http://www.apcc.com/">APC
<option value="http://se.asus.com//">Asus
<option value="http://www.atitech.ca/">Ati
<option value="http://www.benq-eu.com/">Benq
<option value="http://www.brother.se/">Brother
<option value="http://www.dlink.se/products/">Dlink
<option value="http://www.hp.se/">HP
<option value="http://www.hgst.com/">IBM/Hitachi
<option value="http://www.logitech.com/cf/country.cfm?PATH=/">Logitech
<option value="http://www.minolta-qms.se/">Minolta QMS
<option value="http://www.netgear.se">Netgear
<option value="http://www.pcstuff.philips.com/">Philips
<option value="http://www.plextor.com/">Plextor
<option value="http://www.ricoh.co.jp/cd-r/e-/e_europe/index.html">Ricoh
<option value="http://www.samsung.se/">Samsung
<option value="http://www.verbatim.co.uk/">Verbatim
<option value="http://www.support.zyxel.se/">Zyxel Support
<option value="http://www.zyxel.se/">Zyxel Produkter
</select>
</span></a>


----------



## Moderith (Dec 14, 2007)

Try

<option selected disabled>Tiilverkare

That should make it unselectable.


----------



## DonaldG (Aug 23, 2007)

<select name="select" onChange="window.open(options[selectedIndex].value)">

is an explicit command to open a new window. I'm very rusty and for the life of me, I can't think of another way of opening in the same window...


.Parent ??? or something ...


----------



## DonaldG (Aug 23, 2007)

According to Javascript 1.3 (all I have):


The 'window' object always refers to the current window, the one that contains the script. The 'self' keyword is also a synonym for the current window...

Try self.open as in:
<select name="select" onChange="self.open(options[selectedIndex].value)">


----------



## DonaldG (Aug 23, 2007)

document.location.replace();

<select name="select" onChange="window.open(options[selectedIndex].value)">

Instead of above, try this:
<select name="select" onChange="document.location.replace(options[selectedIndex].value)">


----------



## tajjyarden (Dec 20, 2007)

What you might try doing is calling a custom function from the onchange event.


```
<select onchange="myOpenWindow(this.value)">
```
Then at the bottom of your page


```
<script type="text/javascript">
<!--

function myOpenWindow(value){
    if (value == "http://www.3com.se/" | 
        value == "http://www.acercomputer.se/" | 
        value == "http://www.apcc.com/" | 
        value == "http://se.asus.com/"){
        window.open(value)
    }
}

-->
</script>
```
That way in the function myOpenWindow() function you can list the websites that you want to cause a window to open. The others will be ignored. Hope it helps!


----------

