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

Thread: Form addition

  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form addition

    I have been playing around with this working code:

    <script language="JavaScript" type="text/javascript">
    <!--
    function search_google(){
    window.open("http://www.google.com/search?q="+document.search.query.value);
    }
    //-->
    </script>
    <form name="search">
    <input type="text" name="query" value="">
    <input type="submit" value="Search Google" onClick="search_google()">
    </form>

    If I type for example 'feet' into the form it produces the query string
    Code:
    http://www.google.com/search?q=feet
    which is fine but ....

    I would like to modify the script to produce a query string like this
    Code:
    http://www.google.com/search?q=feet+site%3Amyfootshop.com
    with the additional text provided by a hardcoded variable such as additionaltext=+site%3Amyfootshop.com

    I know it must be quite easy but I am new to JavaScript.

    Thank you for any help.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    PHP would be better for this as it has a url_encode function. Why the need for javascript? Can you not run php on your server?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Javascript does too.

    Code:
    encodeURIComponent("feet and hands")
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #4
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How would I use the encodeURIComponent to concatenate the form input with a variable as above?

    Thanks.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function search_google(){
    var x = encodeURIComponent(document.search.query.value)
    window.open("http://www.google.com/search?q="+x);
    return false;
    }
    //-->
    </script>
    </head>
    <body>
    <form name="search" onSubmit="return search_google()">
    <input type="text" name="query" value="">
    <input type="submit" value="Search Google">
    </form>
    </body>
    </html>
    Last edited by _Aerospace_Eng_; 09-09-2006 at 04:16 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much for the help!


  •  

    Posting Permissions

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