473,748 Members | 2,161 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 1289
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
4264
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
2706
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
6606
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
1577
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
1951
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
55308
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
2432
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
1474
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
1914
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
2504
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
8822
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,...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9236
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
8235
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...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.