473,856 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Values from a form replacing spaces with a "+"

2 New Member
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 1294
rohypnol
54 New Member
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
aqualuvaro
2 New Member
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

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

Similar topics

2
4269
by: \Dandy\ Randy | last post by:
Hello everyone. I have been following misc posts, as well as reading several FAQ's on this issue, unfortunatley I cannot locate a solution. I am hoping that someone will be able to provide me with the simple answer. My problem has to do with the leading white spaces after the first line when calling data using the @ variable. Here is my code: open (PREVIEW, "<preview.txt") or &error("Unable to open the data file for reading"); flock...
3
2713
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their "name" property (which sources from "name" HTML attribue). The problem is, that if the form contains form control named "name", it overwrites the form name property. In fact, I'm quite surprised that it's so easy to spoil any of the form object...
6
6616
by: Dan | last post by:
I wish to replace all the occurrances of " with &quot; within a string. I have tried using myString.Replace("\"", "&quot;"), but this does not work Any suggestions will be greatly appreciated Thanks
2
1580
by: Rob Meade | last post by:
Hi all, I am getting the above error when I try to flick from HTML to Design view in Visual Studio - I get the jist of the error message, and I know the line of code which it refers to which is this; <asp:TemplateColumn> <ItemTemplate>
7
1955
by: Rich | last post by:
Hi, I was experimenting with some basic sample asp code but can't get it to work correctly: this is bgselector.asp which works OK - you add the name of a basic color like blue, green, yellow and call another asp called backcolor.asp where I have the problem: bgselector.asp
6
55432
by: gdjoshua | last post by:
New to C##.. All I want to do is add spaces to a string I'm displaying in label? Anybody know the easiest way to do this. char(32) doesn't seem to be working...
6
2437
by: KiwiGenie | last post by:
Hi..I am trying to make a search form. I am fairly new to access and could well be looking at it completely wrong. I have an unbound form with textboxes in the header for entering different search criteria. I have a subform for displaying the results, which is bound to Query4. SQL for Query4 (taken from sql view in query): SELECT tblRecipes.RecipeName, tblRecipes.FoodCategory, Sum(Query3.IngredCost) AS SumOfIngredCost, Query3.RecipeID FROM...
6
1479
by: Deano | last post by:
Every once in a while I modify one particular form (could be anything from adding code to tweaking properties as far as I can see) and upon loading I get; "You can't assign a value to this object" The form is now completely blank and I can only see anything if I switch to design view. I am kaking changes that will break the form admittedly but those are bugs of course and I expect to be able to fix them.
3
1924
by: eBob.com | last post by:
How does a "sub-form", i.e. one invoked by another form, determine anything about the form which brought it into existence, i.e., I suppose, instantiated it? I wanted to so something like this ... MsgBox("called by " & Owner.Name) .... but that throws a null reference exception. Parent.Name and ParentForm.Name also throw null reference exceptions. Form1.Name works - but that's not very flexible.
1
2513
by: StuartD | last post by:
I have a sub form that is populated based on the selection of a year from a combo box on the main form. I'm trying to add a second main form combo box for item category to further filter the sub form; however, I'd like the item category combo box to be interpreted as "all values" if no selection is made. I've tried using an IIf statement in the underlying query of the sub form to either use the value of the item category combo box if it has a...
0
9904
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11051
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10693
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10378
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9527
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4170
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.