För att flytta inmatade värden till en annan sida är denna kod användbar. Det som är aningens irriterande är att mellanslag ersätts med plustecken. Frågan är alltså om det går att ersätta dessa + med just ett mellanslag, alltså precis så som det matats in?
<!-- THREE STEPS TO INSTALL PASSING VALUES:
1. Copy the form code into the first page with the form
2. Paste the HEAD code into the second HTML page
3. Add the final code into the BODY of your second page -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<BODY>
<center>
<form type=get action="passing-values-source.html">
<table border=1>
<tr>
<td>First Name:</td>
<td><input type=text name=firstname size=10></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type=text name=lastname size=10></td>
</tr>
<tr>
<td>Age:</td>
<td><input type=text name=age size=3></td>
</tr>
<tr>
<td colspan=2><input type=submit value="Submit!">
</td>
</tr>
</table>
</form>
</center>
<!-- STEP TWO: Paste this code into the HEAD of your second document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! [url]http://javascript.internet.com[/url] -->
<!-- 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>
</HEAD>
<!-- STEP THREE: Put this on the page that should read the values -->
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");
// End -->
</script>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.23 KB -->