How to transferring form data through Url "Get" method?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spencer Killen
    New Member
    • Jan 2011
    • 10

    How to transferring form data through Url "Get" method?

    Hey I have a short little poll thing and i'd like to transfer the results to another page through url like
    ...com/?x=12&y=55 hers what I got so far:
    by the way my website doesn't let me use the post method
    Code:
    <form name="input" action="index2.htm" method="get">
    Name: <input type="text" name="user" /> <br />
    <input type="radio" name="sex" value="male" /> Male<br />
    <input type="radio" name="sex" value="female" /> Female <br />
    <input type="checkbox" name="Bike" value="Yes" /> I have a bike<br />
    <input type="checkbox" name="Car" value="Yes" /> I have a car <br />
    <input type="submit" value="Submit" />
    I'd like the site index2.htm to display something like: "Name is a male and has a bike But not a Car
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    this code should work like that.

    Comment

    • AutumnsDecay
      New Member
      • Mar 2008
      • 170

      #3
      You SHOULD be getting something like:

      index2.htm?user =username&sex=m ale&bike=I%20ha ve%20a%20bike

      Or something similar.

      I find it weird that you're unable to post. What version of PHP is the server running?

      Comment

      • Spencer Killen
        New Member
        • Jan 2011
        • 10

        #4
        oh my gosh okay it works fine i get a url like
        index2.htm?user =username&sex=m ale&bike=I%20ha ve%20 a%20bike
        But on that page I want to take those varibles and make a sentence like: Hello bob you are male and you have a car and a bike

        Also the post method doesn't work because I have a sub-domain through webs.com and I doesn't allow the post method.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          you can use JavaScript for that. the object of interest is window.location .search

          Comment

          • Spencer Killen
            New Member
            • Jan 2011
            • 10

            #6
            ok i managed to find this code
            Code:
            <html>
            <head>
            <script language="JavaScript">
            
            function onload()
            {
            alert(window.location.search);
            }
            
            </script>
            </head>
            
            <body onLoad="onload()">
            
            </body>
            </html>
            whats with the "alert" or "onload" do i need them, and if im right this will return them as javascript variables?

            I used this code just to test it and it didn't woek
            Code:
            <head>
            <script language="JavaScript">
             
            function onload()
            {
            alert(window.location.search);
            }
             
            document.write(sex);
            
            
            </script>
            
            </head>

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              window.location .search returns that part of the URI between file address and anchor target. you have to break up that string into the relevant parts. it does not do the break-up automatically.

              Comment

              • Spencer Killen
                New Member
                • Jan 2011
                • 10

                #8
                G0T IT
                thanks Dormilich

                Code:
                <script type="text/javascript">
                <!--
                
                function querySt(ji) {
                hu = window.location.search.substring(1);
                gy = hu.split("&");
                for (i=0;i<gy.length;i++) {
                ft = gy[i].split("=");
                if (ft[0] == ji) {
                return ft[1];
                }
                }
                }
                
                var koko = querySt("sex");
                
                document.write(koko);
                document.write("<br>");
                document.write(hu);

                Comment

                Working...