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

C

chirs

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
 
K

kaeli

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
-------------------------------------------------
 
H

Hywel Jenkins

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;">
 
S

Sergey I.Grachyov

Use this:

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top