Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: onsubmit url

  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy onsubmit url

    hello

    what i m trying to do is when i press submit, it will redirect me to a url with the values that i submited in the form ..

    what wrong i m doing .. thanks in advance

    <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 city = document.forms[0].city.value;
    var state = document.forms[0].state.value;
    window.parent.location.href=url+'?city='+city+'&state='+state;
    return false;
    }
    </script>
    </head>
    <body>
    <form action="" method="get" onsubmit="return goTo()">

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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    It is totally senseless to use Javascript for this. The functionality you describe is the basic functionality for HTML forms and can (and should) easily be accomplished using only HTML. But you are missing the URL, which you will have to add to the "action" attribute of the form
    Code:
    <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>
    </head>
    <body>
    <form action="yoururl.php" method="get">
    
    <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>


  •  

    Posting Permissions

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