View Full Version : query string

05-21-2009, 07:11 PM
Goal: get query string and email the sting upon users submitting form.
Reason: To know what marketing ad unit the user can from

Look for some help. I need to get a query sting from the url (ex. example.htm?id=22e&moreid=99lk) and store the stings as vars and be able to pass these vars from page to page (hidden from the user) and when the user gets to a registration form and submits the form, the vars get attached to the email that is sent to me, so I know where they came from.

Is this idea possible and feasible in Javascript, if so can someone point me in a driection?

Philip M
05-21-2009, 07:49 PM
You can capture the query string as follows:-

alert (location.href.substring(n));

where n is a number representing the first character of the text you wish to capture, that is the one following the ?.

You can the write this out to a cookie, the value of which is added to a hidden field in your form.

However, the trouble with using mailto: to send form results is its unpredictability. The method it is highly dependent on the browser in use and the email client in use (some people have only Yahoo or Hotmail). In particular, some of the most popular versions of Internet Explorer/Outlook Express will not work correctly. With all of the browser troubles, you're likely to lose about half of your users' messages. Most of the email clients that can successfully send a mail will prompt the user by a security dialog prior to sending - this can scare many users from continuing. Also, what about people with Javascript disabled?

In fact few browsers these days accept mailto: as a form action. You need a really old browser for it to work as more modern browsers simply open the email program (if any) and ignore the form. If you are going to use a form for your registration then use a server-side formmail script as the action - there are several good free ones out there.

Haikus are easy
But sometimes they don't make sense.

05-21-2009, 08:08 PM
Yeah, I already have an online form that does a lot of stuff, I was just looking to capture the query string form the initial landing page, and have it carry through the visit and when/if they fill out the form the query string data would attach itself to the form via hidden values and when the form is submitted an email gets sent to me and I then I can see the query string (which was the initial landing page the landed on).

However, you are suggesting the only way to do this with javascript is with a cookie?

Philip M
05-21-2009, 09:47 PM