471,896 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. <form name="input" action="index2.htm" method="get">
  2. Name: <input type="text" name="user" /> <br />
  3. <input type="radio" name="sex" value="male" /> Male<br />
  4. <input type="radio" name="sex" value="female" /> Female <br />
  5. <input type="checkbox" name="Bike" value="Yes" /> I have a bike<br />
  6. <input type="checkbox" name="Car" value="Yes" /> I have a car <br />
  7. <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
Jan 6 '11 #1

✓ answered by Dormilich

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.

7 2206
Dormilich
8,658 Expert Mod 8TB
this code should work like that.
Jan 6 '11 #2
AutumnsDecay
170 100+
You SHOULD be getting something like:

index2.htm?user=username&sex=male&bike=I%20have%20 a%20bike

Or something similar.

I find it weird that you're unable to post. What version of PHP is the server running?
Jan 6 '11 #3
oh my gosh okay it works fine i get a url like
index2.htm?user=username&sex=male&bike=I%20have%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.
Jan 6 '11 #4
Dormilich
8,658 Expert Mod 8TB
you can use JavaScript for that. the object of interest is window.location.search
Jan 6 '11 #5
ok i managed to find this code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="JavaScript">
  4.  
  5. function onload()
  6. {
  7. alert(window.location.search);
  8. }
  9.  
  10. </script>
  11. </head>
  12.  
  13. <body onLoad="onload()">
  14.  
  15. </body>
  16. </html>
  17.  
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
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script language="JavaScript">
  3.  
  4. function onload()
  5. {
  6. alert(window.location.search);
  7. }
  8.  
  9. document.write(sex);
  10.  
  11.  
  12. </script>
  13.  
  14. </head>
  15.  
Jan 7 '11 #6
Dormilich
8,658 Expert Mod 8TB
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.
Jan 7 '11 #7
G0T IT
thanks Dormilich

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. function querySt(ji) {
  5. hu = window.location.search.substring(1);
  6. gy = hu.split("&");
  7. for (i=0;i<gy.length;i++) {
  8. ft = gy[i].split("=");
  9. if (ft[0] == ji) {
  10. return ft[1];
  11. }
  12. }
  13. }
  14.  
  15. var koko = querySt("sex");
  16.  
  17. document.write(koko);
  18. document.write("<br>");
  19. document.write(hu);
  20.  
Jan 7 '11 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Gregory A Greenman | last post: by
5 posts views Thread by Peter | last post: by
4 posts views Thread by Alex Sibilev | last post: by
7 posts views Thread by Mark Waser | last post: by
1 post views Thread by Asaf | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.