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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cookies to Remember Fields

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>AllComponents Quote Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="style.css" type="text/css">
    </head>
    
    <body>
    <div align="center"> 
      <form name="quoteform" method="POST" action="">
        <table width="470" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="101">SALES REP:</td>
            <td width="149"><input name="SalesRep" type="text" id="SalesRep"></td>
            <td width="86"><div align="right">CUST. #:</div></td>
            <td width="134" colspan="-1"><input name="CustomerNumber" type="text" id="CustomerNumber"></td>
          </tr>
          <tr> 
            <td>PHONE #:</td>
            <td><input name="PhoneNumber" type="text" id="PhoneNumber"></td>
            <td><div align="right">CUST. NAME:</div></td>
            <td colspan="-1"><input name="CustomerName" type="text" id="RecipEmail"> 
            </td>
          </tr>
          <tr> 
            <td>FAX #:</td>
            <td><input name="FaxNumber" type="text" id="FaxNumber"></td>
            <td colspan="2"><input type="checkbox" name="Remember" value="Remember">Remember Me</td>
          </tr>
          <tr> 
            <td>REP EMAIL:</td>
            <td><input name="RepEmail" type="text" id="RepEmail"></td>
            <td><input type="submit" value="Submit" name="submit" class="sbttn"></td>
            <td colspan="-1"><input type="reset" name="Reset" value="Reset Form" class="sbttn"></td>
          </tr>
        </table>
      </form>
    </div>
    </body>
    </html>
    This can be seen HERE.

    I would like to set a cookie that remembers every field on the left column. The right columns will have to be manually filled in every time. Is this doable?
    Last edited by sftl99; 07-07-2005 at 12:31 AM.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Yes and no.
    There is a limit of 20 cookies per domain. If this is a sample, not the full thing, you may run into issues and have to use less cookies structured to save more than one field per cookie.
    Also, the user can disallow cookies.
    Also, some browsers remember what the user entered and you can only try to override that.

    But, basically and in theory, sure you can.
    Just set the cookies with name/value pairs with your language of choice. You can set with javascript before the form submits or you can set with your server-side language after the form submits.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is a sample, but on the real deal there will only be the four fields just as in the example. It is for internal use so everyone will have cookies enabled. This is just a small sample of a large quote form that all of us sales reps will be using. I would like cookies so that each sales rep would save time and not have to enter their name, number, fax, and email every time. Does that make sense? Can anybody help me on this one?

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    What do you need help with?
    Do you know how to set/get cookies?
    http://www.ipwebdesign.net/useful_cookies.html

    Do you not understand when to set them or ... ?

    I'm happy to help, just not sure what you need help with.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To be quite honest, I've only dealt with cookies once and it was a long time ago and it wasn't this function at all. I am basically starting from scratch.

    There are four text boxes that I want to be "saved" into a cookie and automatically populated next time the user goes to the page. See www.jasonpcarroll.com/allcomponents/test.html and you might get an idea of what I'm trying to do.

    The user of this form will be entering the same information into the four left column text boxes every time, so in order to save time, I figured I would set a cookie for those 4 fields so that the next time the user pulled up the page, those fields would already be populated.

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    If this is for internal use, do all your users have MSIE?
    Because if they do, you can just persist the form.
    http://msdn.microsoft.com/workshop/a...e/overview.asp

    Otherwise, let me know and I'll post a simple script to do it.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A lot of us, including myself are using FireFox.

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Yeah, I like Firefox better, too.

    Here ya go. I just set two of them to show you. You do the rest.
    The cookie functions are in the link I posted before. I use those functions here.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>AllComponents Quote Form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="style.css" type="text/css">
    <script type="text/javascript" src="cookies.js"></script>
    <script type="text/javascript">
    function fillFields()
       {
       var f = document.forms["quoteform"];
       
       var c_SalesRep = getCookie("SalesRep");
       if (c_SalesRep != "") f.SalesRep.value = c_SalesRep;
    
       var c_PhoneNumber = getCookie("PhoneNumber");
       if (c_PhoneNumber != "") f.PhoneNumber.value = c_PhoneNumber;
    
       }
    
    function saveFields(frm)
       {
       setCookie("SalesRep", frm.SalesRep.value, 365);
       setCookie("PhoneNumber", frm.PhoneNumber.value, 365);
       }
    </script>
    </head>
    
    <body onLoad="fillFields()">
    <div align="center"> 
      <form name="quoteform" method="GET" action="" onSubmit="saveFields(this)">
        <table width="470" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="101">SALES REP:</td>
    
            <td width="149"><input name="SalesRep" type="text" id="SalesRep"></td>
            <td width="86"><div align="right">CUST. #:</div></td>
            <td width="134" colspan="-1"><input name="CustomerNumber" type="text" id="CustomerNumber"></td>
          </tr>
          <tr> 
            <td>PHONE #:</td>
            <td><input name="PhoneNumber" type="text" id="PhoneNumber"></td>
            <td><div align="right">CUST. NAME:</div></td>
    
            <td colspan="-1"><input name="CustomerName" type="text" id="RecipEmail"> 
            </td>
          </tr>
          <tr> 
            <td>FAX #:</td>
            <td><input name="FaxNumber" type="text" id="FaxNumber"></td>
            <td colspan="2"><input type="checkbox" name="Remember" value="Remember">Remember Me</td>
          </tr>
          <tr> 
            <td>REP EMAIL:</td>
    
            <td><input name="RepEmail" type="text" id="RepEmail"></td>
            <td><input type="submit" value="Submit" name="submit" class="sbttn"></td>
            <td colspan="-1"><input type="reset" name="Reset" value="Reset Form" class="sbttn"></td>
          </tr>
        </table>
        <p>I only want the left column to be saved, the CUST# and NAME are to be manually 
          entered each time. How can I set a cookie for those four fields?</p>
        <p>The &quot;Remember Me&quot; box does not need to be enabled, I just thought 
          it would be a cool feature. In other words, I don't mind if the cookie is 
          set regardless of the checkbox...if that feature is too hard, I'll just 
          eliminate it.</p>
    
        <p>This page is just a small sample of a larger page, but even on that larger 
          page I will only have 4 fields that need to be set.</p>
      </form>
    </div>
    </body>
    </html>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    Regular Coder
    Join Date
    Apr 2005
    Location
    austin, tx
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works perfectly now. I sure appreciate it!

  • #10
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You're welcome!

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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