Jump to content

get GET data using javascript

Featured Replies

i need a form that someone can fill out, and which will then redirect them to another page which displays stuff (or not) dependant on the way that they filled out the form.

 

I also need the form to save its data using GET, so that the URL can be copied and passed to someone else, who can then view the page.

 

In other words, i need a form that will allow someone to 'customise' a webpage for someone else.

 

now... i can't play about with any server-side gubbins; the only way i can conditionally display stuff is using javascript.

 

which i dont know :-(

 

i've got as far as figuring out stuff like

 

<script type="text/javascript">
if (variable1 == yes)
(
document.write ("you chose variable one")
)
</script>

 

but the thing that i can't figure out is how to grab the GET data that is stored in the URL using javascript? I've googled about for ages, and can't find it anywhere.

 

if anyone knows how to do this, i'd greatly appreciate it if they would tell me :)

  • Author

there's no easy way to do it?

 

poop.

 

still... i've just discovered the 'split' thing, and i'm having fun :) i've allready managed to get one of the GET thingies.

 

<h3>Hello<script type="text/javascript">
var url = window.location.href
var url2 = url.split("?")
var username = url2[1]
var username2 = username.split("=")
if (username2[0] == "username")
{
var username3 = username2[1]
var username4 = username3.split("&")
document.write (" " username4[0])
}
</script>, and welcome...</h3>

 

(i know the last document.write bit's wrong btw)

 

whilst kinda fun, this strikes me as the long way of doing this, and i think the fun's going to evaporate as soon as i get onto the rest of the GET data :-(

Yes, that's the only way to do it.

 

You could always wrap it in a function though and let that do all the dirty work for you :)

 

Cheers,

 

Ryan Jones

  • Author

man, i finally did it.

 

that was such a pain in the arse.

 

cheers both.

What did the final code look like? (just outta interest)

  • Author

it's on this page ;)

 

There's another page that generates the url.

 

(theyre just demos of an idea atm)

 

it wasn't actually that hard in the end, just very confusing :D

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.