...

View Full Version : target = blank problem



DimisD
02-26-2007, 12:41 AM
Hi there,

I have the form below and i want when the checkbox is checked, or when the second drop down menu selected "_blank", to open in a new window.
Can somebody help??

thank you



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE=javascript>
function go() {

location=document.form1.menu.options[document.form1.menu.selectedIndex].value;
target=document.form1.menu2.options[document.form1.menu2.selectedIndex].value;

// OR USING A BOX THE CODE WOULD BE????
// if (document.form1.checkbox.checked == true) { target="blank");

}
</SCRIPT>
</head>

<body>
<form name="form1" >
<select style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" name="menu">
<option value="http://www.google.com" selected>Gooooogleit</option>
<option value="http://www.yahoo.com">Yahoooooit</option>
</select>
<input style="font-size:12px;color:#ffffff;font-family:verdana;background-color:#006699;" type="button" onClick="go()" value="Go">
<p>&nbsp;</p>

<select style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" name="menu2">
<option value="parent" selected>parent</option>
<option value="blank">blank</option>
</select>


<input type="checkbox" name="checkbox" value="_blank" checked="checked" />

</form>

</body>
</html>

rwedge
02-26-2007, 03:31 AM
location is a reserved word, so try this:
<SCRIPT LANGUAGE=javascript>
function go() {
loc=document.form1.menu.options[document.form1.menu.selectedIndex].value;
target=document.form1.menu2.options[document.form1.menu2.selectedIndex].value;
if (target=='blank') var win = window.open(loc);
else location.href=loc;
}
</SCRIPT>

Rappa
02-26-2007, 03:41 AM
dosn't "blank" have an underscore before it? (_blank) or is that html?

_Aerospace_Eng_
02-26-2007, 05:09 AM
It does have the underscore in front but in this case it doesn't really matter as the script posted as a solution is using window.open for the new window rather than just setting the forms target to _blank besides in HTML Strict and XHTML Strict the target attribute has been deprecated because it was considered a behavior. Since JS is good at behaviors we use js to create the new windows.

Bill Posters
02-26-2007, 09:13 AM
It does have the underscore in front but in this case it doesn't really matter as the script posted as a solution is using window.open for the new window
Fwiw, it does make a difference.

As in markup, the second, target argument of the window.open method functions similarly to the target attribute in markup.

e.g.

window.open('blah.html','blank'); // one reusable window

window.open('blah.html','_blank'); // new window every time



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum