user818671
user818671

Reputation: 399

read cookies in javascript

On textbox onchange property i have called one javascript function In that I have written this,

function testbox1()
{

var strline1side1 = document.frmartwork.side1textbox1.value;
document.cookie="lineside1="+strline1side1.replace(" "," ")+";path=/;";

}

I want to assign this "lineside1" cookie value when page is reload

window.onload=function()
{

document.frmartwork.side1textbox1.value = "here i want that cookie "


}

How can i do this?

Upvotes: 0

Views: 238

Answers (2)

Samich
Samich

Reputation: 30095

If you are using jQuery - use jQuery.cookies plugin. It's quiet simple to use.

$.cookies('cookiename') // get value
$.cookies('cookiename', value) // set value

function testbox1()
{
    $.cookies('lineside1', $('#side1textbox1').val());
}

$(document).ready(function(){
    $('#side1textbox1').val($.cookies('lineside1'));
});

Also, if you start using jQuery - use it :)

Upvotes: 0

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76870

You should use jquery cookie plugin

function testbox1()
{

var strline1side1 = document.frmartwork.side1textbox1.value;
$.cookie('lineside1',strline1side1.replace(" "," "));

}

window.onload=function()
{

document.frmartwork.side1textbox1.value = $.cookie('lineside1')


}

Upvotes: 2

Related Questions