PDA

View Full Version : combo boxes and how to change the go button to open in a new pop up window


smm
03-05-2003, 11:57 PM
How can I change this combo box code so that the GO button opens in a new pop up window instead of the same window?


<form name="doublecombo">
<p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Technology Sites</option>
<option>News Sites</option>
<option>Search Engines</option>
</select>
<select name="stage2" size="1">
<option value="http://javascriptkit.com">JavaScript Kit</option>
<option value="http://www.news.com">News.com</option>
<option value="http://www.wired.com">Wired News</option>
</select>
<input type="button" name="test" value="Go!"
onClick="go()">
</p>

<script>
<!--

/*
Double Combo Script Credit
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScripts here!
*/

var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("JavaScript Kit","http://javascriptkit.com")
group[0][1]=new Option("News.com","http://www.news.com")
group[0][2]=new Option("Wired News","http://www.wired.com")

group[1][0]=new Option("CNN","http://www.cnn.com")
group[1][1]=new Option("ABC News","http://www.abcnews.com")

group[2][0]=new Option("Hotbot","http://www.hotbot.com")
group[2][1]=new Option("Infoseek","http://www.infoseek.com")
group[2][2]=new Option("Excite","http://www.excite.com")
group[2][3]=new Option("Lycos","http://www.lycos.com")

var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//-->
</script>

</form>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>

cheesebagpipe
03-06-2003, 01:44 AM
http://www.codingforums.com/showthread.php?threadid=14552&highlight=select+new+window

smm
03-06-2003, 12:41 PM
I still cant get the script to work

Here is the script


<script language="JavaScript">
function goto(objSel) {
if (objSel.selectedIndex > 0) {
win = window.open(objSel.options[objSel.selectedIndex].value ,'','width=800,height=600');
win.focus();
}
}
//-->
</script>
</p>
<form>
<p align="center">
<select name="select" onchange="goto(this)" size="1">
<option value="">-----------Roof Tiles----------</option>
<option value="http://www.redland.co.uk/">Redland</option>
<option value="http://www.marleyroofing.co.uk/">Marley Roofing</option>
</select>
</p>
</form>



<script>
<form name="doublecombo">
<p align="center">
<select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Roof Tiles</option>
<option>Roof Batten</option>
<option>Clay Roof Tiles</option>
<option>Ventilation and Underlay</option>
<option>Insulation</option>
<option>Roof Slates</option>
</select>
<select name="stage2" size="1">
<option value="http://www.redland.co.uk/">Redland</option>
<option value="http://www.marleyroofing.co.uk/">Marley Roofing</option>
</select>
&nbsp;
<input name="button" type="button" onClick="jumpbox()" value="Go!">
<div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><em><br>
</em></font>
<script>

<!--

/*
Double Combo Script Credit
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScripts here!
*/

var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("Redland","http://www.redland.co.uk/")
group[0][1]=new Option("Marley Roofing","http://www.marleyroofing.co.uk/")


group[1][0]=new Option("John Brash","http://www.johnbrash.co.uk/")


group[2][0]=new Option("Keymer","http://www.keymer.co.uk/")
group[2][1]=new Option("Michelmersh","http://www.michelmersh.co.uk/")
group[2][2]=new Option("Tudor Roof Tiles","http://www.tudorrooftiles.co.uk/")


group[3][0]=new Option("Klober","http://www.klober.co.uk/")
group[3][1]=new Option("Calenders Vulcanite","http://www.calendersvulcanite.co.uk/")

group[4][0]=new Option("Warren","http://www.warren.co.uk/")
group[4][1]=new Option("Tyvek","http://www.tyvekhome.com/")

group[5][0]=new Option("Stoneleaf Slates","http://www.stoneleafslates.co.uk/")

var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//-->
</script>
</div>
</form>:(

GoHF
03-06-2003, 01:00 PM
Hey dude, see the go() function? I think it's all about that.

try replacing it with this one:

function go(){
win = window.open(temp.options[temp.selectedIndex].value,'','');
win.focus();
}

this will open a new window and bring it on top of all other (focus on it). I don't know, however, if on the second attempt it will open in another new window or in the same new window. Good luck.

smm
03-06-2003, 02:11 PM
I have just tried that and it still wont work

videocaptain
12-09-2003, 03:02 AM
Hi, I've just inserted the javascript for the double combo box and I'm having the same problem. I want it to open up in a new window.

Does anybody know how to help me with this?

John

videocaptain
12-09-2003, 03:09 AM
Actually, GoHF is correct.

It does have to do with the GO function...therefore, this code works for me...I just tried it.

function go(){
win = window.open(temp.options[temp.selectedIndex].value,'','');
win.focus();
}


Thank you for helping me out! Much appreciated! :)

glenngv
12-09-2003, 03:11 AM
Originally posted by smm
I have just tried that and it still wont work

Is your code like this?

<input type="button" name="test" value="Go!"
onClick="go()">
...
function go(){
var win = window.open(temp.options[temp.selectedIndex].value,'_blank','width=800,height=600');
win.focus();
}

videocaptain
12-09-2003, 03:56 AM
glenngv,

Do you know how to open up a new window while clicking on a rotating banner script?

something to do with the function and target="_blank"

Any idea?

Katana62678
01-08-2004, 01:35 PM
Originally posted by glenngv
Is your code like this?

<input type="button" name="test" value="Go!"
onClick="go()">
...
function go(){
var win = window.open(temp.options[temp.selectedIndex].value,'_blank','width=800,height=600');
win.focus();
}


I am also one struggling with this problem. The above works, but is there a way to have only one of the drop down selections spawn a new pop-up window, while all the rest continue to open in the current page?

-Thanks in advance for any help

glenngv
01-09-2004, 10:26 AM
You have to tell which option spawns a new window and which ones do not by adding additional data in the option value and delimited by a character that cannot be found in a URL.

group[0][0]=new Option("Redland","1|http://www.redland.co.uk/"); //1=new window; 0=same window
group[0][1]=new Option("Marley Roofing","0|http://www.marleyroofing.co.uk/");
...
function go(){
var arr = temp.options[temp.selectedIndex].value.split('|');
if (arr[0]) { //new window
var win = window.open(arr[1],'_blank','width=800,height=600');
win.focus();
}
else location.href=arr[1]; //same window
}

Katana62678
01-09-2004, 01:20 PM
Originally posted by glenngv
You have to tell which option spawns a new window and which ones do not by adding additional data in the option value and delimited by a character that cannot be found in a URL.

group[0][0]=new Option("Redland","1|http://www.redland.co.uk/"); //1=new window; 0=same window
group[0][1]=new Option("Marley Roofing","0|http://www.marleyroofing.co.uk/");
...
function go(){
var arr = temp.options[temp.selectedIndex].value.split('|');
if (arr[0]) { //new window
var win = window.open(arr[1],'_blank','width=800,height=600');
win.focus();
}
else location.href=arr[1]; //same window
}



Thanks, I am still having trouble getting this to run without error. Applying the above code and making necessary changes, it then wants to open all links in a new window. I am going to continue to play with it.

glenngv
01-10-2004, 01:44 PM
Did you put a 0 in the option value?

group[0][1]=new Option("Marley Roofing","0|http://www.marleyroofing.co.uk/");