jQuerybeast
jQuerybeast

Reputation: 14490

On form submit get LocalStorage Item and submit it

I'm trying to get a localStorage item and set a form's attribute but it doesn't seem to work which localStorage is used.

The localStorage item 'formitem' has value "somevalue".

This is what I currently have which doesn't work:

$(".form").submit(function() {
        if (localStorage.getItem("formitem") == "somevalue"){ 
            $(".form").attr('action', 'http://www.google.com')
        }else {$(".form").attr('action', 'http://www.bing.com')}
});

What I'm I doing wrong?

Upvotes: 1

Views: 375

Answers (1)

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this

$(".form").submit(function() {
        if (parseInt(localStorage["formitem"]) == 1){ 
            $(".form").attr('action', 'http://www.google.com')
        }else {$(".form").attr('action', 'http://www.bing.com')}
});

Upvotes: 2

Related Questions