Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Need JavaScript Code to open URL

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-04-2012
Member
 
Join Date: Sep 2010
Posts: 12
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 ?

Reply With Quote
  #2  
Old 12-04-2012
Member
 
Join Date: Aug 2010
Posts: 35
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);
Reply With Quote
  #3  
Old 12-04-2012
Member
 
Join Date: Aug 2010
Posts: 63
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>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Need JavaScript Code to open URL"
Thread Thread Starter Forum Replies Last Post
How to replace HTML code using javascript visioneye Software Development 6 11-05-2010 11:38 PM
How to Open Popup Window in Javascript? Soumen Software Development 4 07-02-2010 03:02 AM
How to Open PDF with JavaScript? Silent~Kid Software Development 4 06-02-2010 02:28 AM
Javascript code in servlet Aaliya Seth Software Development 5 14-01-2010 06:02 PM
How to convert Javascript code to Html code Bosch Software Development 3 21-09-2009 01:20 PM


All times are GMT +5.5. The time now is 10:05 AM.