Forum Moderators: open

Message Too Old, No Replies

form open in new page

adding target blank

         

santapaws

5:42 pm on Mar 2, 2009 (gmt 0)

10+ Year Member



can anyone tell me how to have this form open in a new window? Thanks.

<head>
<script type="text/javascript">
function getURL(val){
base = 'http://www.domain.com/';
location = base + val;
return false;
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return getURL(this.url.value)">
<label>
<input type="text" name="url" />
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
</body>
</html>

LifeinAsia

5:59 pm on Mar 2, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Did you try the following?

<form id="form1" name="form1" method="post" action="" onsubmit="return getURL(this.url.value)" target="_blank">

santapaws

6:46 pm on Mar 2, 2009 (gmt 0)

10+ Year Member



thanks but that no workie!

LifeinAsia

7:01 pm on Mar 2, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Bizarre- worked when I tried it. That's just basic HTML.

Hang on- just looked at your first post. You have
return false;
at the end of your function, which prevents your form from being submitted.
Change to
return true;

santapaws

7:11 pm on Mar 2, 2009 (gmt 0)

10+ Year Member



thanks for taking the time to look at that and well spotted :)
only thing is that now it works as a popunder, the target page isnt appearing above the form page but below in both firefox and ie7.

rocknbil

11:34 pm on Mar 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can anyone tell me how to have this form open in a new window?

Another approach, as target is deprecated in XHTML (even though I'm using html 4.01 here):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>New Window</title>
<script type="text/javascript">
window.onload=function() {
if (document.getElementById) {
document.getElementById('form1').onsubmit=function() {
return getURL(document.getElementById('url').value);
}
}
}
function getURL(val){
if (val=='') { alert('Please enter a url or file name.'); }
else {
val = 'http://www.example.com/'+val;
var day = new Date();
var id = day.getTime();
var params='width=600,height=600,scrollbars,resizable';
var win=open(val,id,params);
}
return false;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label for="url">URL:</label>
<input type="text" name="url" id="url">
<input type="submit" name="SubmitButton" value="Submit">
</form>
</body>
</html>

santapaws

8:55 am on Mar 3, 2009 (gmt 0)

10+ Year Member



that works just right. Thanks.

llCloNEll

8:11 pm on May 27, 2009 (gmt 0)

10+ Year Member



I know this post is a bit old but its exactly what i was browsing hours for with one minor problem.

I am trying to do the exact same thing but with multiple inputs. Basically something like....

www.blah.com/blah/ + input1 + text + input2 + moretext

This posts helps me out up until i want to add in input2 how would i got about this?

Heres what im working with atm....... Everything works fine until i add in the form1.Url2.value how would i go about this.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>New Window</title>
<script type="text/javascript">
window.onload=function() {
if (document.getElementById) {
document.getElementById('form1').onsubmit=function() {
return geturl(document.getElementById('url').value);
}
}
}
function geturl(val){
if (val=='') { alert('Please enter a url or file name.'); }
else {
val = 'www.blah.com/'+val+'text'+form1.url2.value+'text';
var day = new Date();
var id = day.getTime();
var params='width=600,height=600,scrollbars,resizable';
var win=open(val,id,params);
}
return false;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label for="url">URL:</label>
<input type="text" name="Input1" id="url" value="First">
<input type="text" name="Input2" id="url2" value="Last">
<input type="submit" name="SubmitButton" value="Submit">
</form>
</body>
</html>

[edited by: llCloNEll at 8:13 pm (utc) on May 27, 2009]

enigma1

9:44 am on May 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You leave the original geturl as it was.

you need to pass another argument for the 2nd input. This is the first one
document.getElementById('url').value;
you need another one for the second
document.getElementById('url2').value

so get the values first
url1 = document.getElementById('url').value;
url2 = document.getElementById('url2').value;

then you pass both to the geturl function
return geturl(url1+url2);

llCloNEll

1:37 pm on May 28, 2009 (gmt 0)

10+ Year Member



Thank you enigma1 works flawlessly :). So simple was right in front of my eyes but i couldn't get a grasp on it.