Reputation: 14490
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
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