Carry value from one page to a confirmation page

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?
dale4brumbaughAsked:
Who is Participating?
 
dankuckConnect With a Mentor Commented:
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
 
cx323Commented:
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
 
dankuckCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
dale4brumbaughAuthor Commented:
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
 
dale4brumbaughAuthor Commented:
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
 
dankuckCommented:
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
 
dale4brumbaughAuthor Commented:
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
 
dale4brumbaughAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.