Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    (another) document.write problem EDITED: Fixed Old Problem/Have New Problem

    So not a programmer here, but I can implement simple code when required. I needed a piece of JavaScript to allow me to set a cookie on Page 1 and then call it on Pages 2-4. Page 2 and Page 4 are forms that are submitted anonymously via email (php), and the cookie is used to provide an ID number for users that automatically gets populated as they move through the pages. Being the non-programmer that I am, it's taken me several hours to get the cookie working (in FF only, not yet in IE). It is working now, but when the data are sent via email, the ID variable doesn't show up. The code for calling the cookie inside the form (and it does display properly on the page) is as follows:

    <SCRIPT LANGUAGE="javascript">
    document.write("Unique ID ");
    </SCRIPT>
    <SCRIPT LANGUAGE="javascript">
    document.write("<INPUT TYPE=text SIZE=10 VALUE=" +YouWrote+ ">");
    </SCRIPT>

    Where YouWrote is the cookie. I'm fairly sure what's wrong is that I'm missing a piece of code to tell it that the variable should be a permanent part of the form, but I have no idea what that code might be.

    Any and all help is greatly, greatly appreciated. Thank you so much.

    cheers,
    Stephanie

    ***Edited Request For Help

    All right. I have the code working beautifully, thanks to trolling the web and getting missing bit I needed. However, the code is only working in FF and not in IE. In IE, when the ID should be displayed in the text box on Page 2, the code instead returns the value "undefined." As well, when the form is emailed, the variable value in the email reads "undefined."

    The code used to set the cookie is as follows:

    <SCRIPT LANGUAGE="JavaScript">
    cookie_name = "dataCookie";
    var MitCookie;
    function putCookie() {
    if(document.cookie != document.cookie)
    {index = document.cookie.indexOf(cookie_name);}
    else
    { index = -1;}
    if (index == -1)
    {
    MitCookie=document.id.uniqueid.value;
    document.cookie=cookie_name+"="+MitCookie+"; expires=3600";
    }
    }
    </SCRIPT>


    The code used to retrieve the cookie on Page is as follows:

    <SCRIPT LANGUAGE="JavaScript">
    cookie_name = "dataCookie";
    var MitCookie;
    function getName() {
    if(document.cookie)
    {
    index = document.cookie.indexOf(cookie_name);
    if (index != -1)
    {
    namestart = (document.cookie.indexOf("=", index) + 1);
    nameend = document.cookie.indexOf(";", index);
    if (nameend == -1) {nameend = document.cookie.length;}
    MitCookie = document.cookie.substring(namestart, nameend);
    return MitCookie;
    }
    }
    }
    MitCookie=getName();
    if (MitCookie == "dataCookie")
    {MitCookie = "Nothing_Entered"}
    </SCRIPT>
    <SCRIPT language="javascript" for="oBody" event="onload()">
    MitigationPhaseIDemographics.hiddenelement.value = GetCookie("MitCookie")
    </SCRIPT>


    Finally, the code used to write the code to the text box is as follows:

    <SCRIPT LANGUAGE="javascript">
    document.write("Unique ID ");
    </SCRIPT>
    <SCRIPT LANGUAGE="javascript">
    document.write("<INPUT TYPE=text name=unique_id SIZE=10 VALUE=" +MitCookie+ ">");
    </SCRIPT>


    Again, all help is appreciated greatly. Thanks so much!

    cheers,
    Stephanie
    Last edited by swweeks; 09-02-2006 at 10:42 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •