Passing variables with javaScript

I decided to take on a little more advanced technique so I looked into how to pass variables using javaScript. I know how to do this using php sessions and cookies, but didn't know how this was done using javaScript. So, I created a "process" page for which my form gives data. The data is passed through a "get" method in the url. I found a free piece of code at http://javascript.internet.com that will filter and extract the first and last name out of the url. Here is the function:

<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
	function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
	var pairs = document.URL.substring(idx+1,
	document.URL.length).split('&');
	for (var i=0; i<pairs.length; i++) {
	nameVal = pairs[i].split('=');
	params[nameVal[0]] = nameVal[1]; } }
	return params; }
	params = getParams();
//  End -->
</script>
          

After applying this code to the head, all that was needed was to place the variables in line with the text. Below is the code that goes in the text. Try the form, I think this is pretty cool, but then again, I am somewhat easy to please when it comes to code that actually works!

<h1>Thank you, 

		<SCRIPT LANGUAGE="JavaScript">
		firstname = unescape(params["fname"]);
		lastname = unescape(params["lname"]);
		document.write(firstname);
		document.write(" " + lastname + "<br>");
		</script>

for signing up for our newsletter!</h1>
          

So if you have a chance, fill out the form and submit it. I will take you to the process page and hopefully, your first and last name will be brought into the page.