469,315 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Values from a form replacing spaces with a "+"

Hi all,
In advance, thanks for any help. I'm an absolute newbie to javascript so any help is much appreciated.

(see code below) I have two html pages, form values are entered into one & displayed on the other, however, the spaces between words are showing as a plus sign instead.

Any idea how to fix this so they are just spaces & not plus signs?

Thanks!!

Expand|Select|Wrap|Line Numbers
  1. function callinput(key) 
  2. if(window.location.href.indexOf(key+'=')!=-1) 
  3. a=window.location.href.split("?")[1].split(key+"=")[1].split("&")[0]; 
  4.  
  5. <!--cleanup data--> 
  6. a=unescape(a); 
  7. a=a.replace(/\+/," "); 
  8.  
  9.  
  10. document.write(a); 
  11. else 
  12. alert("Not all fields were filled. Please re-enter them."); 
  13. history.go(-1); 
  14. //--> 
and this is the code that "gets" the value (I think??)
Expand|Select|Wrap|Line Numbers
  1. script language="javascript" type="text/javascript">
  2.  
  3. <!-- 
  4. callinput("store") 
  5. //--> 
  6. </script>
Jul 28 '08 #1
2 1103
Simple:
Use a <form> tag with method="POST" in the parent page and do a server-side check. Have the server decide if the fields were entered correctly or not and then redirect the user using the "Location" header. You should also do the check on the client, prior to submitting the form (in it's onsubmit event) and warn the user about errors and prevent the page from submitting. If you do this, you MUST still do server-side checks because JavaScript is easy to hack and anyone could submit wrong information to your server.

Complicated:
If you must stick to JavaScript and method="GET" for this kind of check, use a piece of JavaScript that encodes all the fields prior to sending the form (ie, in the form's onsubmit event) and then decode them when you read them right after line 5. You could use this script http://www.webtoolkit.info/javascript-base64.html and call it like so:
Expand|Select|Wrap|Line Numbers
  1. formElement.value = Base64.encode(formElement.value); // in the onsubmit event of the previous page
  2. a = Base64.decode(a); // in the callinput() function you just pasted
Also, don't forget to decode the fields on the server side if you're processing them somehow, I'm not aware of any server-side scripting language that doesn't implement some way to decode base64-encoded values.
Jul 28 '08 #2
Simple:
Use a <form> tag with method="POST" in the parent page and do a server-side check. Have the server decide if the fields were entered correctly or not and then redirect the user using the "Location" header. You should also do the check on the client, prior to submitting the form (in it's onsubmit event) and warn the user about errors and prevent the page from submitting. If you do this, you MUST still do server-side checks because JavaScript is easy to hack and anyone could submit wrong information to your server.

Complicated:
If you must stick to JavaScript and method="GET" for this kind of check, use a piece of JavaScript that encodes all the fields prior to sending the form (ie, in the form's onsubmit event) and then decode them when you read them right after line 5. You could use this script http://www.webtoolkit.info/javascript-base64.html and call it like so:
Expand|Select|Wrap|Line Numbers
  1. formElement.value = Base64.encode(formElement.value); // in the onsubmit event of the previous page
  2. a = Base64.decode(a); // in the callinput() function you just pasted
Also, don't forget to decode the fields on the server side if you're processing them somehow, I'm not aware of any server-side scripting language that doesn't implement some way to decode base64-encoded values.
BRILLIANT!! Thank you so much!
Jul 28 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by \Dandy\ Randy | last post: by
6 posts views Thread by Dan | last post: by
6 posts views Thread by gdjoshua | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.