Thiago
Thiago

Reputation: 1555

Cookie problem - cookie's not defined

Guys, I'm having a trouble with a cookie.

The error:

"linhaOS" isn't defined.

I wanna know if the cookie is null in the beggining of code.

$("#pApresentacao").click(function _click(){    



if ($.cookie("exibir") == null)
{   
    if ($("#hdLinhaOsView").val() != ""){i=$("#hdLinhaOsView").val()}
    else {i=0}; 
    $.cookie("exibir",1);
    $.cookie("linhaOS",i);
    _apresentacao(i);
}
else
{

    if ($.cookie("linhaOS") == null){i=0}
    else{i=$.cookie(linhaOS)};

    _apresentacao(i);
};

The first cookie(exibir) is working fine. But the second is not! How is it possible? It is almost the same.

Could someone help me?

Thks folks.

Upvotes: 1

Views: 4241

Answers (3)

jmbucknall
jmbucknall

Reputation: 2061

Looks like the statement that reads the cookie should be reading the string "linhaOS" and not the variable linhaOS.

Upvotes: 1

Ivo Wetzel
Ivo Wetzel

Reputation: 46745

Your problem isn't $.cookie(...) it's that the variable linhaOS is not defined.

else{i=$.cookie(linhaOS)};
                ^-------- If you use a variable you have to defined it
                          but this one doesn't appear anywhere in your code

So how to fix it? Well I suppose you wanted to use $.cookie("linhaOS") once again, and you just forgot to quote it as a string with "". So just quote it as a string, that will fix your problem.

Upvotes: 3

Andy E
Andy E

Reputation: 344567

It looks like you forgot to wrap linhaOS in string delimiters. Change

else{i=$.cookie(linhaOS)};

to

else{i=$.cookie("linhaOS")};

Upvotes: 2

Related Questions