[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Carry value from one page to a confirmation page

Posted on 2007-07-25
8
Medium Priority
?
320 Views
Last Modified: 2012-08-14
I have a form that has a confirmation page on submit.  Is there an easy way to take the value from 1 textbox and carry it over to the confirmation page either into another textbox or just as text?
0
Comment
Question by:dale4brumbaugh
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:cx323
ID: 19571632
I would recommend not doing this in javascript because some people have it disabled for various reasons.  If you still want to you can use cookies to store the data on the first page and then recall it on the confirmation page.

http://www.w3schools.com/js/js_cookies.asp
0
 
LVL 1

Expert Comment

by:dankuck
ID: 19579969
I assume you are only using JavaScript and then passing the information to a server-side script that you have no control over.

If you can create a second server-side script, it could collect the information and generate your confirmation page with the user data stored in hidden input fields.  If you choose this option, be sure to escape the data when generating the confirmation page.  Stray quotation marks and greater-than signs can get in the way when creating HTML attributes.

If you choose to pass the information via cookies (unrecommended, but not unusual), you should still take care to escape the user data using encodeURIComponent(data) to protect against semicolons and equals signs.  The data can be decoded using decodeURIComponent(encodedData).

As cs323 mentioned, JavaScript may be turned off, but you should also be aware that cookies may be turned off separately from JavaScript.  Presumably, this can be tested simply by attempting to set a cookie and then checking to see that it was set.
0
 

Author Comment

by:dale4brumbaugh
ID: 19580011
For the time being, I think I will use Javascript.  However, I don't have a lot of experience with it.  See if you see a problem with the following:
On my source page where the value is set, I call this function with the onClick event for the submit button:
-------------

function setCookie (_ResNumber, mydate, expdate) {
    var expdate = new Date ();
        expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 1));
        setCookie ("_ResNumber", mydate, expdate);
    }  
-------------
In my confirmation page I call the following function with the body load:
-------------
 function getCookie (_ResNumber) {
    var dcookie = document.cookie;
    var cname = _ResNumber + "=";
    var clen = dcookie.length;
    var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) {
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
    return null;
document.Confirmation.ResNumber.value=(getCookie("_ResNumber"));
}
-----------

Currently I am getting an error when clicking submit.  My data is being emailed in the process and this feature is still working, however I am not getting to the confirmation page to see if the cookie is being retrieved.  (I suspect it is not and that the error is in setting the cookie)
Please note that I don't have ready access to the server that is hosting my site.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Accepted Solution

by:
dankuck earned 1500 total points
ID: 19580279
Your setCookie function appears to loop infinitely by calling itself.  I think you meant something like this:

function setCookie (_ResNumber, mydate, expdate) {
    var expdate = new Date ();
        expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 1));
        document.cookie = _ResNumber + "=" + escape(mydate) + "; expires=" + expdate;
    }  
        setCookie ("_ResNumber", mydate, expdate);

Your getCookie function would usually work (although the last line wouldn't run, I think you meant to put it outside the {}).  

This line has one problem:

cbegin = dcookie.indexOf(" ", cbegin) + 1;

It treats a space as the delimiter for cookies instead of a semicolon and therefore it sometimes checks parts of the values to see if they equal cname.  This could cause obscure problems if the name of one cookie was found within the value of another cookie.  This could be used instead:

cbegin = dcookie.indexOf("; ", cbegin) + 2;
0
 

Author Comment

by:dale4brumbaugh
ID: 19585581
In the set cookie, the mydate variable is being generated with vbscript.  Will this variable still be passed through the setCookie function or do I have to pass it somehow to the function in javascript?
0
 
LVL 1

Expert Comment

by:dankuck
ID: 19586161
A cursory test suggests that it will work just fine.

The following correctly displays the date in Internet Explorer 6, so I assume the same would work for your other method:

<html>
<body>


<script language="javascript">

      function jsAlert(text){
            alert(text);
      }

</script>

<script language="vbscript">

      jsAlert Date

</script>

</body>
</html>
0
 

Author Comment

by:dale4brumbaugh
ID: 19596838
Thanks for the last tidbit.  I am having some trouble with the whole cookie thing.  It doesn't appear to be setting it (checking my system for it after going to the page).  Other than cookies and Javascript, are there any other alternatives to do this?
0
 

Author Comment

by:dale4brumbaugh
ID: 19596948
here is something odd.  I am doing this work in the forbidden Frontpage and using default properties of the form.  When I set the confirmation page, it works just fine, so long as the confirmation page DOES NOT have a form associated with it.  If I lay a form on the confirmation page, it will give a Frontpage error from the site.  Has anyone seen this?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question