/    Sign up×
Community /Pin to ProfileBookmark

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 [url]http://javascript.internet.com/forms/passing-values.html[/url]

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.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@pyroJul 17.2003 — You could use a regular expression like this:

<script type="text/javascript">
str = "This+is+a+test";
str = str.replace(/+/g," ");
alert (str);
</script>
Copy linkTweet thisAlerts:
@pmo200gauthorJul 17.2003 — 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.
Copy linkTweet thisAlerts:
@pyroJul 17.2003 — 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," ");
Copy linkTweet thisAlerts:
@pmo200gauthorJul 17.2003 — Pyro,

It worked perfectly. Thanks.
Copy linkTweet thisAlerts:
@pyroJul 17.2003 — You're welcome... ?
Copy linkTweet thisAlerts:
@Jeff_MottJul 17.2003 — [b]using the script on http://javascript.internet.com/form...ing-values.html[/b][/quote]That 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 [thread]162208[/thread].
×

Success!

Help @pmo200g spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...