How to refer to a value of an input box within the <input...> tag?

Discussion in 'Javascript' started by chirs, Oct 17, 2003.

  1. chirs

    chirs Guest

    Hi,

    I want to put a value in a cookie. The following code does not work.
    It does not store the box1.value in the cookie. How can I fix it?
    <input type="text" name="box1" onblur=document.cookie="user=" +
    box1.value>

    Chris
     
    chirs, Oct 17, 2003
    #1
    1. Advertising

  2. chirs

    kaeli Guest

    In article <>,
    enlightened us with...
    > Hi,
    >
    > I want to put a value in a cookie. The following code does not work.
    > It does not store the box1.value in the cookie. How can I fix it?
    > <input type="text" name="box1" onblur=document.cookie="user=" +
    > box1.value>
    >
    > Chris
    >


    Try
    <input type="text" name="box1" onblur="setCookie('user',this.value,'')">

    The function setCookie is as follows.

    function setCookie(cookieName, cookieValue, expireDate)
    {
    /* Pass in three strings - the name of the cookie, the value, and the
    expire date.
    Pass in a "" empty string for expireDate to set a session cookie
    (no expires date).
    Pass in any other date for expire as a number of days to be added
    to today's date. */

    if (expireDate == "")
    {
    expires = "";
    }
    else
    {
    expires = new Date();
    expires.setDate(expires.getDate() + expireDate);
    expires = expires.toGMTString();
    }
    document.cookie = cookieName+"="+cookieValue+";expires="+expires;
    }

    --
    -------------------------------------------------
    ~kaeli~
    Jesus saves, Allah protects, and Cthulhu
    thinks you'd make a nice sandwich.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    -------------------------------------------------
     
    kaeli, Oct 18, 2003
    #2
    1. Advertising

  3. In article <>,
    says...
    > Hi,
    >
    > I want to put a value in a cookie. The following code does not work.
    > It does not store the box1.value in the cookie.


    Hardly surprising - the syntax is wrong.

    > How can I fix it?
    > <input type="text" name="box1" onblur=document.cookie="user=" +
    > box1.value>


    <input type="text"
    name="box1"
    onblur="document.cookie='user=' + document.FormName.box1.value;">


    --
    Hywel I do not eat quiche
    http://hyweljenkins.co.uk/
    http://hyweljenkins.co.uk/mfaq.php
     
    Hywel Jenkins, Oct 18, 2003
    #3
  4. Use this:

    <input type="text" name="box1" onblur='document.cookie="user=" +
    this.value'>

    --
    Sergey.
    http://www.takereal.com/freelance/resume.asp


    > Hi,
    >
    > I want to put a value in a cookie. The following code does not work.
    > It does not store the box1.value in the cookie. How can I fix it?
    > <input type="text" name="box1" onblur=document.cookie="user=" +
    > box1.value>
    >
    > Chris
     
    Sergey I.Grachyov, Oct 18, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashutosh
    Replies:
    3
    Views:
    9,055
    Andrew Thompson
    Jun 16, 2005
  2. shruds
    Replies:
    1
    Views:
    965
    John C. Bollinger
    Jan 27, 2006
  3. cjl
    Replies:
    1
    Views:
    10,554
    Michael Winter
    Oct 31, 2005
  4. Replies:
    21
    Views:
    16,767
    Harlan Messinger
    Dec 14, 2007
  5. cjl
    Replies:
    7
    Views:
    219
    Thomas 'PointedEars' Lahn
    Oct 30, 2005
Loading...

Share This Page