Click to See Complete Forum and Search --> : passing info


pmo200g
07-17-2003, 08:45 AM
I was wondering if anyone could lend me a hand. I am fairly new to javascripting, but I have used some of the scripts available on this web site.

I am attempting to pass information from a form on one page to a second page using the script on http://javascript.internet.com/forms/passing-values.html

I have gotten it to work, however, I am interested in modifying it to allow sentences, or longer strings of text. As it is written, the results would show a "+" in between each word. I am interested in finding out how to get rid of these "+" signs.

I appreciate any help that can be provided.

pyro
07-17-2003, 08:51 AM
You could use a regular expression like this:

<script type="text/javascript">
str = "This+is+a+test";
str = str.replace(/\+/g," ");
alert (str);
</script>

pmo200g
07-17-2003, 09:11 AM
Pyro,

Thanks for the option. I tried it out, and it worked as it's meant to, but it didn't affect the data that I had passed using the form.

The intention is to have the user fill out a form, submit it, and be presented with their information in a table format for them to print out. I could do this with a database, but the technology that I am working with makes that difficult. I found a script that allows the passing of single words or number strings without any difficulty, however, if I try to put in two or more words I get the plus sign between each word. Here is the script as it is written:

_____________

In the body of the submission page:

<form type=get action="rubric-complete.html">
<table border=1>
<tr>
<td>First Name:</td>
<td><input type=text name=firstname size=10></td>
</tr>
<tr>
<td>Middle Name:</td>
<td><input type=text name=middlename 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>

____________________

In the head of the results page:

<SCRIPT LANGUAGE="JavaScript">

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();
</script>

____________________

And in the body of the results page:

<SCRIPT LANGUAGE="JavaScript">


firstname = unescape(params["firstname"]);
middlename = unescape(params["middlename"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);

document.write("<center><table border=1><tr><td>firstname = " + firstname + "</td></tr>");
document.write("<tr><td>middlename = " + middlename + "</td></tr>");
document.write("<tr><td>lastname = " + lastname + "</td></tr>");
document.write("<tr><td>age = " + age + "</td></tr></table></center>");

</script>

If you can think of any way to get the plus signs out of the results table, I would love to hear about it.

pyro
07-17-2003, 09:46 AM
You could do this:

firstname = unescape(params["firstname"]);
firstname = firstname.replace(/\+/g," ");
middlename = unescape(params["middlename"]);
middlename = middlename.replace(/\+/g," ");
lastname = unescape(params["lastname"]);
lastname = lastname.replace(/\+/g," ");
age = unescape(params["age"]);
age = age.replace(/\+/g," ");

pmo200g
07-17-2003, 09:51 AM
Pyro,

It worked perfectly. Thanks.

pyro
07-17-2003, 09:53 AM
You're welcome... :)

Jeff Mott
07-17-2003, 11:19 AM
using the script on http://javascript.internet.com/form...ing-values.htmlThat isn't actually a very good script. The semi-colon is also a valid delimiter, which that script ignore. If cannot handle multiple values, as in the case of multiple select menus or checkboxes. And, as you have discovered, it does not perform any kind of URL decode. A better alternative is 162208.