469,927 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

open new window

Hi,

I have this code in the head of the page:

script language="JavaScript" type="text/JavaScript">
<!--

function goTo(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

and this bit in the body section:

<form name="form1" method="post" action="">
<select name="select" onChange="goTo('self',this,0)">

Simple put I want the new page to open in a new window, I assumed that
changing the 'self' bit to 'blank' would work but all I get are JavaScript
undefined error messages.

Does anybody have any other ideas as to what I could try ?

Thanks

Jul 23 '05 #1
2 2119
"Andy" <an******@hotmail.com> writes:

script language="JavaScript" type="text/JavaScript">
The language attribute is deprecated and can safely be omitted
<!--
This HTML comment starter can also safely be omitted.

function goTo(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
Yikes. Bad use of eval. You will probably never need to use eval, as
there are better alternatives.

Just use:
function goTo(tObj,selObj,restore) {
tObj.location=selObj.options[selObj.selectedIndex].value;
...
and
<form name="form1" method="post" action="">
<select name="select" onChange="goTo('self',this,0)">
onchange="goTo(self,this,false);"

Simple put I want the new page to open in a new window, I assumed that
changing the 'self' bit to 'blank' would work but all I get are JavaScript
undefined error messages.
This code is only built to open in existing windows.
Does anybody have any other ideas as to what I could try ?


function goToNew(winName,selObj,restore) {
var win = window.open(selObj.options[selObj.selectedIndex],winName);
if (restore) {selObj.selectedIndex=0;}
return win;
}

called as, e.g.:
onchange="goToNew('_blank',this,false);"

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
On Sat, 17 Apr 2004 20:42:42 +0100, Andy <an******@hotmail.com> wrote:
I have this code in the head of the page:

script language="JavaScript" type="text/JavaScript">
The language attribute is deprecated, and the presence of the type
attribute makes it redundant. Remove it.
<!--
Script hiding is a practice that is now obsolete. Remove the SGML comment
delimiters.
function goTo(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
Why are you using eval()? I don't see why you can't just make targ an
object reference and then write:

targ.location.href = selObj.options[ selObj.selectedIndex ].value;

Notice that there is no need to convert the value property to a string.
The form control values are *always* returned as strings.
if (restore) selObj.selectedIndex=0;
}
//-->
Remove this delimiter along with the first.
</script>

and this bit in the body section:

<form name="form1" method="post" action="">
<select name="select" onChange="goTo('self',this,0)">
To work with the changes above, change the call to

goTo(self,this,false)

I changed the last argument to false because it makes more sense to pass
booleans when evaluating booleans.
Simple put I want the new page to open in a new window, I assumed that
changing the 'self' bit to 'blank' would work but all I get are
JavaScript undefined error messages.
That's because "self" is an object reference to the current window
(equivalent to window.self or window), whereas "blank" isn't defined at
all.
Does anybody have any other ideas as to what I could try ?


A call to window.open(), perhaps?

Two things to note:

1) Don't perform navigation actions on the "change" event.
2) Avoid new windows completely, if possible.

If I use my mouse wheel to change the value, the event will fire every
time even though I probably haven't chosen a destination yet. Similarly,
if I make a mistake when choosing a value, I will not get an opportunity
(unless I'm very quick) to correct it. Use a button instead.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Les | last post: by
10 posts views Thread by Marshall Dudley | last post: by
10 posts views Thread by David McCulloch | last post: by
2 posts views Thread by Samir Pandey | last post: by
3 posts views Thread by NeverLift | last post: by
2 posts views Thread by Larry R Harrison Jr | last post: by
8 posts views Thread by Dominic Tocci | last post: by
7 posts views Thread by anthony.turcotte | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.