开发者

Javascript - Input field On Change Set Cookie of Value

开发者 https://www.devze.com 2023-04-07 14:22 出处:网络
Thanks to anyone in advance that can help me in my issue. I\'m simply trying to save the value of a form input type=\"text\" to a cookie when the input value has changed. Think I almost had i开发者_高

Thanks to anyone in advance that can help me in my issue.

I'm simply trying to save the value of a form input type="text" to a cookie when the input value has changed. Think I almost had i开发者_高级运维t, but I cannot get it to work.

Here is what I have so far

-This is the javascript Set_cookie Function.

function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

-This is the Function that is suppose to save the input on change.

$(document).ready(function () {
    $('#inputText1').change(function () {
      Set_Cookie( 'inputText1', .val($(this)), '', '/', '', '' );
    });
});

-Input Field

input type="text" name="inputText1" id="inputText1"

Thanks again to anyone who can help.


Give this project a try

http://plugins.jquery.com/project/Cookie

And this tutorial will help you

http://www.komodomedia.com/blog/2008/07/using-jquery-to-save-form-details/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号