Forum Moderators: open
<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>
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>
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]
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);