Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to display these values w/ spaces, not pluses

Status
Not open for further replies.

Nokios

Technical User
Sep 14, 2000
12
0
0
US
I have this script on my soon-to-be-up website that does display the values entered on a second page. But when it is displayed, all the spaces within the entered values are turned to pluses. I know this is normal, but is there something I can add to this script, or a different script I can use?

The Form tag on the first page :

<form name=&quot;form1&quot; action=&quot;file:///P|/Desktop/Computer Applications/CAWT - Project 1 - TEC/printoutfinal.htm&quot;>

The script inside the head of the page displaying it :
[ignore]
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
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.split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();
</script>
[/ignore]
And one of the script lines that displays the value :
[ignore]
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
Name = unescape(params[&quot;Name&quot;]);
document.write(Name);
</script>
[/ignore]
If you have anything that I can do to this to make these darn pluses remain as spaces, please let me know.
My email is nokios@post.com
 
I'm not that far into JavaScript, what exactly do you mean?
change the unescape to escape?
 
I hate to sound even less knowledgable of JavaScript, but... heh.. how? [sig][/sig]
 
You need to do some research on using events in Javascript. Assuming that you're using a submit button to submit the form, declare a onsubmit handler for the form, and in that handler, escape each value on the form.

Code:
<script language='Javascript'>
function submitHandler(frm){
   for (var i=0;i<frm.elements.length;i++)
        if (frm.elements[i]) 
               frm.elements[i].value = escape(frm.elements[i].value);
   return true;
}
</script>

<form action=&quot;mypage&quot; method=&quot;post&quot; onsubmit=&quot;return submitHandler(this)&quot;>
<input type=...
</form>
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
I put the first part in the header and then the body, but it only changed it in the forms, and so when it was displayed, it put the syntax that represents a space, &quot;%20&quot;, and then it puts some more weird syntax in... Any other ideas? [sig][/sig]
 
I'll post them up around 3:30 pm eastern time, so be ready to look at them then. [sig][/sig]
 
Apparently the only way to get the results you want is to replace the + that gets transferred.

Remove the submitHandler stuff from the first page. It only compounded the problem.

In the second page, you'll need to replace the plus signs with spaces:

//do this only once
var plus=/\+/g

//do this for each value
Name = Name.replace(plus,' ');


Anybody have an alternate method? [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Thanks man. It's working just fine, there's just a few things that it still converts to syntax, such as the # and the /, but hey, that doesn't really matter. Now I finish it up, adjust the links and load the whole thing up on the school site, thanks.

Nokios
(Trenton C) [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top