fgict
asked on
Javascript - Open in same Window
Hi,
Once the user selects a Town and clicks "Go" I wish the selected page to open in the same window and not load to "_blank" as it does at present. (see code below)
<SELECT id=discover style="FONT: 11px Arial; WIDTH: 120px; HEIGHT: 18px" name=select>
<OPTION value="" selected>Choose Region:</OPTION>
<OPTION value="../towns/town.asp?I D=1">Town1 </OPTION>
<OPTION value="../towns/town.asp?I D=2">Town2 </OPTION>
<OPTION value="../towns/town.asp?I D=3">Town3 </OPTION>
<OPTION value="../towns/town.asp?I D=4">Town4 </OPTION>
<OPTION value="../towns/town.asp?I D=5">Town5 </OPTION>
</SELECT>
<SCRIPT type=text/javascript>
<!--
function jumptolink(what){
var selectedopt=what.options[w hat.select edIndex]
var URL=selectedopt.value
window.open(URL)
}
//-->
</SCRIPT>
<A style="FONT-WEIGHT: bold; LEFT: 0px; WIDTH: 18px" onclick="jumptolink(docume nt.getElem entById('d iscover')) " href="javascript:">GO</A>
Once the user selects a Town and clicks "Go" I wish the selected page to open in the same window and not load to "_blank" as it does at present. (see code below)
<SELECT id=discover style="FONT: 11px Arial; WIDTH: 120px; HEIGHT: 18px" name=select>
<OPTION value="" selected>Choose Region:</OPTION>
<OPTION value="../towns/town.asp?I
<OPTION value="../towns/town.asp?I
<OPTION value="../towns/town.asp?I
<OPTION value="../towns/town.asp?I
<OPTION value="../towns/town.asp?I
</SELECT>
<SCRIPT type=text/javascript>
<!--
function jumptolink(what){
var selectedopt=what.options[w
var URL=selectedopt.value
window.open(URL)
}
//-->
</SCRIPT>
<A style="FONT-WEIGHT: bold; LEFT: 0px; WIDTH: 18px" onclick="jumptolink(docume
ASKER
Hi Roonaan
thanks for your response, unfortunately none of the suggested solutions worked :(
thanks for your response, unfortunately none of the suggested solutions worked :(
Can you try adding an alert like so:
alert(URL);
Is the url filled as expected?
-r-
alert(URL);
Is the url filled as expected?
-r-
Try this,
window.open('test.html','_ self','hei ght=200,wi dth=400,st atus=yes,t oolbar=no, menubar=no ,location= no');
if u need more help refer this URL - http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/open_0.asp
Regards - G.
window.open('test.html','_
if u need more help refer this URL - http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/open_0.asp
Regards - G.
ASKER
@ Roonaan
The Javascript alert shows:
../towns/town.asp?ID=4
The Javascript alert shows:
../towns/town.asp?ID=4
Then window.location = URL; should work. Try window.location.href=URL; or window.location.replace(UR L);
-r-
-r-
window.location.href=url should work
ASKER
Sorry none of the examples you sent me worked when I tested it in Internet Explorer, yet it did work when I tried the line window.location=URL; in Firefox
Looks like a bug in IE 6 ?
Looks like a bug in IE 6 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Roonaan,
That did the trick, don't know why that version worked..but it did..many thanks again for all you help and patience!
fgict :)
That did the trick, don't know why that version worked..but it did..many thanks again for all you help and patience!
fgict :)
return false on the onClick is what did it
and it is window.location or window.location.replace(ur l) that is the correct syntax
document.location is deprecated
Alternative would be
<SCRIPT type=text/javascript>
<!--
function jumptolink(what){
return what.options[what.selected Index].val ue
}
//-->
<A style="FONT-WEIGHT: bold; LEFT: 0px; WIDTH: 18px" onclick="this.href=jumptol ink(docume nt.getElem entById('d iscover')) " href="#">GO</A>
WITHOUT the return false
and it is window.location or window.location.replace(ur
document.location is deprecated
Alternative would be
<SCRIPT type=text/javascript>
<!--
function jumptolink(what){
return what.options[what.selected
}
//-->
<A style="FONT-WEIGHT: bold; LEFT: 0px; WIDTH: 18px" onclick="this.href=jumptol
WITHOUT the return false
replace window.open(URL); with window.location = URL; or document.location = URL;
-r-