Need JavaScript Code to open URL
I am last year B.Sc.IT student. As a part of my syllabus I am working on live project where I am using java script. I am trying to make a form with different option after hitting submit the JavaScript open a new page with created URL for example:
1) Enter the URL:
user enters: http://www.abc.com
2) 2) Enter the city:
user enters: Chico
3) 3) Enter the state:
user enters: MM
[SUBMIT]
4) Then the following window opens:
http://www.abc.com
I am trying it but encountered with lots of error. Can anyone suggest ma a code for this ?
Re: Need JavaScript Code to open URL
You have to use window.open method in your code to open web application in a new window after Submitting. To do this you have to use following syntax:
Code:
Open (URL, windowName[, windowFeatures])
To open URL of the page to open in the new window.
window.open(http://www.abc.com","mywindow);
Re: Need JavaScript Code to open URL
According to me the coding is much easier in PHP. So try it with following PHP code:
Quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
label {
display:block;
}
</style>
<script type="text/javascript">
function goTo()
{
var url = document.forms[0].url.value;
var city = document.forms[0].city.value;
var state = document.forms[0].state.value;
window.location = url+'?city='+city+'&state='+state;
return false;
}
</script>
</head>
<body>
<form action="" method="get" onsubmit="return goTo()">
<label for="url">Enter the URL:
<input type="text" name="url" id="url">
</label>
<label for="city">Enter the city:
<input type="text" name="city" id="city">
</label>
<label for="state">Enter the state:
<input type="state" name="state" id="state">
</label>
<input type="submit" value="Submit">
</form>
</body>
</html>