Using var passed to function to reference an object
I have just started using the data functions in jQuery for keeping track of a few items on the client.
The user can click on links, which call a function that updates the display and stored data value.
I am storing data as a set of columns, named c1, c2, c3 etc.
I update the relevant column like this
function UpdateCol(column)
{
if(column=='c1') $(#db).data.c1 = "1"
if(column=='c2') $(#db).data.c2 = "1"
.....
}
The above works, but is ugly.
As I want the system to be expandable, I would like to be able to do this
function UpdateCol(column)
{
$(#db).data.column = "1"
}
called as follows....
UpdateCol('c1)
Where "column" is the column named passed to the function. I am having problems, as I don't know how to pass the variable to the .data method to be used as the "key". As I have written it, I think it thinks the key is "column".
Is what I want to do possible...if so please could you advise on the correct way to do it.
Thank you