473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with passing form values

Im trying to send 3 bits of information to another page but I dont know how to do it.

First page:
http://edgwarelocalcars.co.uk/quote3999.html

In the first page, the user types in postcodes in two different form text boxes and upon submission the price is displayed below along with the route being plotted on a google map to the left as well as hiding the "calcualate price button" and showing the "confirm & book" button. Once the button is clicked it takes me to booking2.html with some paramaters at the end. An example is shown below

http://edgwarelocalcars.co.uk/Bookin...ults2=results2

One problem is that results2=results2, (im assuming) there should be a price shown there as in the page quote3999.html, <p id="results2"> shows the price and I was advised to create a hidden input with the same id so that it would pass the name/value along with the addresses.
Expand|Select|Wrap|Line Numbers
  1.                     <p id="results"></p>
  2.  <p id="results2"></p>  <p id="results3"></p>
  3.  
  4.  <input name="price" id="results2" type="hidden" />
  5.  
Heres the script someone made for me which brings (some of) the results to booking2.html. Please note that quote is the name of the form that contains everything.

Expand|Select|Wrap|Line Numbers
  1.     function showLocation() {
  2.     if(document.getElementById('quote').innerHTML!='') { // need to wait for the result from gmaps
  3.     document.forms[0].onsubmit = null;
  4.     document.forms[0].action = 'http://edgwarelocalcars.co.uk/Booking2.html';
  5.     document.getElementById('GMsubmit').style.display = 'none';
  6.     document.getElementById('CBsubmit').style.display = '';
  7.  
[Second Page - http://edgwarelocalcars.co.uk/Booking2.html]

This is the page I wish to display the results. To be more precise, above the table containing the cars. I want the price to be displayed along with the addresses, and also have the price underneath the first car, then for the second I need the price to be displayed with £2 added to it, third car should be the same but £10 added but this bits I will work on later, I just want to concentrate on the values being passed.
At the moment I dont know how to get the address1 and address2 along with the price displayed.
Jan 21 '10 #1

✓ answered by gits

the getParams function could be simplified a bit:
Expand|Select|Wrap|Line Numbers
  1. function getParams() {
  2.     var search        = top.location.search.replace(/^[?]/, '');
  3.     var paramsStrings = search.split('&');
  4.     var params        = {};
  5.  
  6.     for (var i = 0, l = paramsStrings.length; i < l; ++i) {
  7.         var p = paramsStrings[i].split('=');
  8.  
  9.         alert(p[0] + ' = ' + p[1]);
  10.  
  11.         params[p[0]] = p[1];
  12.     }
  13. }
  14.  
instead of the alert do what you want with the params there. The code currently stores the params in a variable ... it might be that you don't need this or use it anywhere as you wish ...

basicly it uses the querystring and extracts the params from it by splitting the string first at the '&' and second at the '='.

kind regards

19 1684
I see in Booking2.html you have a function called getParams. I don't see it ever being called though. And I don't see it populating anything. It just parses the URL and does nothing else.

Is your question how to use this function?
Jan 21 '10 #2
Yes I need help with the function. Ive tried google and tried some codes but I can never figure out what to do. If you can help me I would be very grateful
Jan 21 '10 #3
Here is some code for you to play with. It would replace the code in booking2. I'll look at the quote3999 a little later. Got get some work done.

location.href would return your full query string.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function getParams(location) {
  3.     //var location = location.href;
  4.     var location = "http://edgwarelocalcars.co.uk/Booking2.html?address1=ha8+7ej%C2%A0UK&address2=nw 2+2nj%C2%A0UK&results2=results2&price=2.00"; 
  5.     var idx = location.indexOf('?');
  6.     var str = location.substr(idx + 1, location.length - idx);
  7.     str = str.toString();
  8.     var name = "";
  9.     var value = "";
  10.     var tempArr = new Array();     
  11.     var params = str.split("&");
  12.     for (i = 0; i < params.length; i++) {
  13.         tempArr = params[i].split("=");
  14.         name = tempArr[0];
  15.         value = tempArr[1];
  16.         if (name == "price") {
  17.             document.getElementById("chk1").innerHTML = value;
  18.         }
  19.     }
  20. }
  21. </script>
  22. <body onLoad="getParams()">
  23.     <input type="checkbox" name="ckbox" />
  24.     <p id="chk1"></p>
  25. </body>
  26.  
Jan 21 '10 #4
Thanks! But now I have no idea what do to with this.
Ive Put this on a new page to see how it works and it shows that it displays £2.00 when Using the
Expand|Select|Wrap|Line Numbers
  1. var location = "http://edgwarelocalcars.co.uk/Booking2.html?address1=ha8+7ej%C2%A0UK&address2=nw 2+2nj%C2%A0UK&results2=results2&price=2.00"; 
.
I deleted that and used the locaton.href, then added the
Expand|Select|Wrap|Line Numbers
  1. l?address1=ha8+7ej%C2%A0UK&address2=nw 2+2nj%C2%A0UK&results2=results2&price=2.00
to the end of the page when previewing it but it didnt show the price! Ive even changed "price" to address1 etc but still cant get my head round it!

Ive uploaded the updated version of the page http://edgwarelocalcars.co.uk/Booking2.html
If you dont mind explaing what bit does what in the code you gave me that would greatly help me.

Thanks
Jan 22 '10 #5
gits
5,390 Expert Mod 4TB
the getParams function could be simplified a bit:
Expand|Select|Wrap|Line Numbers
  1. function getParams() {
  2.     var search        = top.location.search.replace(/^[?]/, '');
  3.     var paramsStrings = search.split('&');
  4.     var params        = {};
  5.  
  6.     for (var i = 0, l = paramsStrings.length; i < l; ++i) {
  7.         var p = paramsStrings[i].split('=');
  8.  
  9.         alert(p[0] + ' = ' + p[1]);
  10.  
  11.         params[p[0]] = p[1];
  12.     }
  13. }
  14.  
instead of the alert do what you want with the params there. The code currently stores the params in a variable ... it might be that you don't need this or use it anywhere as you wish ...

basicly it uses the querystring and extracts the params from it by splitting the string first at the '&' and second at the '='.

kind regards
Jan 22 '10 #6
Thanks, yes i think i can make sense of what the code does now, but i still have trouble actually getting it to display the values on the page.
Jan 22 '10 #7
gits
5,390 Expert Mod 4TB
where should what appear?
Jan 22 '10 #8
anywhere on the page. I just need to know how to actually get all the values from the previous page written there.
Jan 22 '10 #9
gits
5,390 Expert Mod 4TB
in a previous post was already a hint ... just put a container to the page like:
Expand|Select|Wrap|Line Numbers
  1. <div id="anyIdYouWantHere"></div>
now in my above code change the alert-line to:
Expand|Select|Wrap|Line Numbers
  1. if ( p[0] == 'price' ) {
  2.     document.getElementById("anyIdYouWantHere").innerHTML = p[1];
  3. }
  4.  
as example for displaying the price in the div.
Jan 22 '10 #10
yes excellent works perfectly BUT now what would I change "+" into a space, as the postcode gets posted like NW2+2NH. Also to add more parameters how would I do this

Expand|Select|Wrap|Line Numbers
  1. if ( p[0] == 'price1' ) {
  2.     document.getElementById("anyIdYouWantHere1").innerHTML = p[1];
  3. }
  4. if ( p[0] == 'price2' ) {
  5.     document.getElementById("anyIdYouWantHere2").innerHTML = p[1];
  6. }
  7.  
would I do another if below it like this?
Jan 22 '10 #11
gits
5,390 Expert Mod 4TB
you could use the replace-function:
Expand|Select|Wrap|Line Numbers
  1. 'NW2+2NH'.replace('+', '&nbsp');
this replaces the + with a html-nonBreakingSpace ... for example

and for the second part ... you could use more if -statements or use the switch-statement:
Expand|Select|Wrap|Line Numbers
  1. switch ( p[0] ) {
  2. case 'price':
  3.     // do something for this case
  4.     break;
  5. case 'price1':
  6.     // do something for this case
  7.     break;
  8. }
which looks a bit cleaner
Jan 22 '10 #12
Thanks so much for your help it works perfectly just ONE las thing. the replace function, where do I put it exactly so that it does it for all values that would go in divbox 1 2 and 3?
Jan 22 '10 #13
gits
5,390 Expert Mod 4TB
just add it where you need it ... to replace before setting it to the document use it like this:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("id").innerHTML = p[1].replace('+', '&nbsp');
Jan 22 '10 #14
Thanks for that, but instead of displaying a space it showed nw2&nbsp2NH but i just changed it to replace '+' with " " and it works fine. Thanks again!
Jan 22 '10 #15
gits
5,390 Expert Mod 4TB
oh ... my bad :) it should have been: &nbsp; ... just forgot the semi-colon. anyway ... good to hear it works now ...
Jan 22 '10 #16
Just realised on the previous page "quote3999.html" it auto adds " UK" at the end of each postcode types, and now it shows as nw2 2nh%C2%A0UK could I just do
document.getElementById("id").innerHTML = p[1].replace('%20uk', '&nbsp;');

edit
it now shows the plus again but no more %20uk
Jan 22 '10 #17
gits
5,390 Expert Mod 4TB
you might simply chain it:
Expand|Select|Wrap|Line Numbers
  1. p[1].replace('+', '&nbsp;').replace('%20UK', '');
Jan 22 '10 #18
Perfect thanks again
Jan 22 '10 #19
gits
5,390 Expert Mod 4TB
you could even use a regExp like this:
Expand|Select|Wrap|Line Numbers
  1. p[1].replace(/(.+)([+])(.+)(%20UK)/, '$1 $3');
Jan 22 '10 #20

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

Similar topics

7
by: grandeandy | last post by:
I have been racking my brain out trying to get this to work... (I am new to javascript)... Below is what I am trying to accomplish. I want to have the areas with +txt+ to have the user defined...
10
by: Joseph S. | last post by:
Hi, How do I pass a string from one call to a php block to another call in the same page but from another form? Here's my full php code: I'm using two forms in the same page. A hidden field...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: MX1 | last post by:
HELP! I have a query that gets a few values from a form. The problem I'm having is a date field in the query. When I put the value in the criteria, it works fine. When I put the same value as...
2
by: Gordon Hudson | last post by:
Hello Here is what I am trying to do: Make a hyperlink on a data entry form with its URL built from the values for fields in that entry on the database. So, I would go to record 65785 click...
4
by: Miguel Dias Moura | last post by:
Hello, i created an ASP.net / VB page with a really big form. Now i want to create 4 pages and in each one i will place 1/4 of the big form. The last page will send all the form values by...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
0
by: ohmp05 | last post by:
Hi all, I am new to deployment of application. If any one please help me on it , that will be great. During the installation of project, Installer will execute an utility( It will display...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
6
by: André | last post by:
Hi, I made a webform for a survey, with multiple-choice questions. The results of each question is put into a table e.g.: values frequency 1 6 2 3 3 32 4 ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.