jquery to dynamically create cookies using the jquery cookie plugin
hey guys,
I am learning jquery and I think for the most part I have the basics down. One of the things that I am attempting to do is to create cookies using the jquery cookie plugin. The idea is that I want to replace as much of the javascript in my code as possible with jquery to see the difficulties in doing it one way or the other. As easy as it seems to be able to create a cookie using the plugin I have not been able to do some successfully and the only thing that I can think of is the way that I am submitting my parameters is not correct. So with that, here is is my code: Code:
//loop over all input file of type text with class prompt Code:
$('input:text, .prompt').each(function(){ |
lmcilwain
I've not used the cookie functionality of jQuery before but you do have a typo in the $.cookie line: Code:
$.cookie($name, $value; |
lmcilwain;
I assume also you have the Cookie plugin? Not sure jQuery does cookies out of the box: http://plugins.jquery.com/project/Cookie Also, what is it that makes you think it doesn't work? Don't rely on that alert statement working right off the bat. You will often fall into a 'race condition' (actually not a real race condition, but close enough) where the time between setting a variable and getting that variable is too quick to expect it to work. Try setting the cookie in jQuery in one function, and then is a separate function try and get it. I've also never seen the '$' syntax used on your own variables. Try this (not tested) Code:
$('input:text, .prompt').each(function(){ Russ |
Yes that was a copy paste issue sorry about that. Yes I do have the cookie plugin installed. Thought it would be nice to know if I installed it right. I simply stuck in the same place where my jquery.js file is and then included it in my html header tags.
Yes I did use the "$" for my variables because that is how I thought jquery used variables. Is that not the case? I also wanted to have a create cookie method but could not figure out how to create another function using jquery code. In javascript I can simply call function someFunction() but in jquery I simply can't figure out how to do that same thing and then call it from within another function. I will give your code a shot in a few minutes and let you know the results, thanks for the quick response. |
I just gave it a shot but it didn't seem to work. I don't see it throwing any errors in the firebug console as well. I will take another look at the documentation again, maybe I am not loading the cookie.js file correctly or something.
|
Quote:
Quote:
1). jquery.min.js (or whatever it's called) 2). cookie.min.js (or whatever it's called) 3). my-custom-js-file.js (or whatever the name of your file is you're working on) ..then you can create function just as you've always done - the difference is now you have the power of jQuery to mix and match as you please. Code:
function getMyID(someID) { Code:
function getMyID(someID) { Good luck Russ |
All times are GMT -5. The time now is 09:02 AM. |