3 Replies - 6663 Views - Last Post: 06 December 2010 - 12:52 PM

#1 Daleaf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-November 10

Pass Data from one page to another

Posted 06 December 2010 - 07:36 AM

Hi im making a web page that asks the user to fill in a order form ranging from drop down and text boxes i want the information that is entered on the first page to be displayed on the second page as a order summary how do i do this?

thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Pass Data from one page to another

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3636
  • View blog
  • Posts: 5,759
  • Joined: 08-June 10

Re: Pass Data from one page to another

Posted 06 December 2010 - 07:51 AM

Hey.

What server-side language are you using to process the data?
If you need the data to be displayed on the second page, you just have your server-side language print the data into the second page.

Basically, using PHP as an example:
<!-- Page: form.html -->

<form action="processData.php" method="post">
    <input type="text" name="theValue"><br>
    <input type="submit">
</form>


<?php
# Page: processData.php

if(isset($_POST['theValue'])) {
    $theValue = $_POST['theValue'];

    # Add the value into the database here, or whatever
    # you plan to do with it.

    # Then print it back into the page.
    echo "<h1>Thank you for your submission</h1>";
    echo "<p>The value you entered is: ". htmlentities($theValue) ."</p>";
}
else {
    echo "<h1>You didn't pass a value. Go back and try again.</h1>";
}
?>


Was This Post Helpful? 0
  • +
  • -

#3 Guest_Daleaf*


Reputation:

Re: Pass Data from one page to another

Posted 06 December 2010 - 07:58 AM

Hey sorry mate, im doing it in javascript. i have got this so far:

function getValue(varname)
{
var url = window.location.href;
var qparts = url.split("?");
if (qparts.length == 0)
{
return "";
}
  var query = qparts[1];
var vars = query.split("&");
var value = "";
for (i=0;i<vars.length;i++)
{
var parts = vars[i].split("=");
if (parts[0] == varname)
{
value = parts[1];
break;
}
}
value = unescape(value);
value.replace(/\+/g," ");
 return value.replace(/\+/g," ");
}



and then to display the data i have:

<input type="text" name="From" id="from" readonly="yes" class="box"> 
<script type="text/javascript">
var name = getValue("From");
document.getElementById("from").value += name;



but i dont understand the first section of getValue, it works but would like it to be explained a bit so that i know what im doing also is there anyway to display it without the tetxtbox it looks a bit weird would be better just as a string

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 06 December 2010 - 08:52 AM

Was This Post Helpful? 0

#4 Guest_Forest51690*


Reputation:

Re: Pass Data from one page to another

Posted 06 December 2010 - 12:52 PM

Well here's what's happening:
Page one gets the data and encodes it into a URL like this:
example.com/page2.html?var1=foo&var2=bar

And then navigates to that URL.

And the second page.. is just a regular page. Without Javascript, none of the data would get displayed. But Javascript runs and it looks at the window.location, which is the same URL as above. It parses out all of the variables:
var1 = "foo"
var2 = "bar"

And then it can use them to display them on the page.

Does that make sense?
- Matthias
Was This Post Helpful? 2

Page 1 of 1