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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open new window with gothere function

Status
Not open for further replies.

jumpmaster82

IS-IT--Management
Sep 7, 2003
13
US
I'm trying to learn java by looking at existing scripts, and I am trying to get this peice of a script to open in a new window. It is a combo box menu which, when selected, will open the linked URL. I'm using the menu in a frame page so when I open it I want a new window.

Here is the script

<form name=&quot;dynamiccombo&quot; target=&quot;_blank&quot;>
<select name=&quot;stage2&quot; size=&quot;1&quot; onChange=&quot;displaysub()&quot;>
<option value=&quot;#&quot;>This is a place Holder text </option>
<option value=&quot;#&quot;>This is a Place Holder text </option>
<option value=&quot;#&quot;>This is a Place Holder text </option>
<option value=&quot;#&quot;>This is a Place Holder text </option>
</select>
<input type=&quot;button&quot; name=&quot;test&quot; value=&quot;Go!&quot;
onClick=&quot;gothere()&quot;>
</form>

<script>
<!--

//STEP 1 of 2: DEFINE the main category links below
//EXTEND array as needed following the laid out structure
//BE sure to preserve the first line, as it's used to display main title

var category=new Array()
category[0]=new Option(&quot;SELECT A CATEGORY &quot;, &quot;&quot;) //THIS LINE RESERVED TO CONTAIN COMBO TITLE
category[1]=new Option(&quot;Command Group&quot;, &quot;combo1&quot;)

//STEP 2 of 2: DEFINE the sub category links below
//EXTEND array as needed following the laid out structure
//BE sure to preserve the LAST line, as it's used to display submain title

var combo1=new Array()
combo1[0]=new Option(&quot;Commanding General&quot;,&quot;cg.htm&quot;)
combo1[1]=new Option(&quot;Command Sergeant Major&quot;,&quot;csm.htm&quot;)
combo1[2]=new Option(&quot;BACK TO CATEGORIES&quot;,&quot;&quot;) //THIS LINE RESERVED TO CONTAIN COMBO SUBTITLE

var curlevel=1
var cacheobj=document.dynamiccombo.stage2

function populate(x){
for (m=cacheobj.options.length-1;m>0;m--)
cacheobj.options[m]=null
selectedarray=eval(x)
for (i=0;i<selectedarray.length;i++)
cacheobj.options=new Option(selectedarray.text,selectedarray.value)
cacheobj.options[0].selected=true

}

function displaysub(){
if (curlevel==1){
populate(cacheobj.options[cacheobj.selectedIndex].value)
curlevel=2
}
else
gothere()
}


function gothere(){
if (curlevel==2){
if (cacheobj.selectedIndex==cacheobj.options.length-1){
curlevel=1
populate(category)
}
else
location=cacheobj.options[cacheobj.selectedIndex].value
}
}

//SHOW categories by default
populate(category)

//-->
</script>

<script language=&quot;JavaScript&quot;>
<!--

Thanks for any help

DJF
 
The line:

location=cacheobj.options[cacheobj.selectedIndex].value

Tells the current browser window to go to the location specified by the selected list item in the combobox.

Something along the lines of:

window.open(cacheobj.options[cacheobj.selectedIndex].value)

Would open a new window.

While looking at other scripts is a great way to learn, it's also a great way to get discouraged. I'd also suggest taking a few step-by-step tutorials... is a beauty.
 
That worked in opening up a new window, but the existing window also changes pages. I would like the combo box to remain and a new window open with the target url.

Thanks so far

DJ
 
Did you remove the line:
[tt]location=cacheobj.options[cacheobj.selectedIndex].value[/tt] ?

Or just add the new one in?
 
I took

location=cacheobj.options[cacheobj.selectedIndex].value

and changed it to

window.open(cacheobj.options[cacheobj.selectedIndex].value)

So the first line no longer appears...BTW, thanks for the web site. It is very good!

DJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top