Results 1 to 3 of 3

Thread: Need JavaScript Code to open URL

  1. #1
    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 ?

  2. #2
    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);

  3. #3
    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:

    <!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>

Similar Threads

  1. How to replace HTML code using javascript
    By visioneye in forum Software Development
    Replies: 6
    Last Post: 11-05-2010, 11:38 PM
  2. How to Open Popup Window in Javascript?
    By Soumen in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 03:02 AM
  3. How to Open PDF with JavaScript?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 02:28 AM
  4. Javascript code in servlet
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 14-01-2010, 06:02 PM
  5. How to convert Javascript code to Html code
    By Bosch in forum Software Development
    Replies: 3
    Last Post: 21-09-2009, 01:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •