0

I am trying to get the ckeip jquery plugin to parse the id of my textarea to my php file.

The plugin is activated by the class name of my textarea:

$('.ckeip_edit').ckeip({

And then data is passed to my php file with an object literal:

data: {
name1     : 'value1',
name2     : 'value2'
      },

I need to use the id attribute of my textarea in one of these so tried:

data: {
name   : 'value',
id     : function(){this.getAttribute("id")}
      },

But this doesn't seem to work.

Can I use variables in an object literal?

Adam Wagner
  • 15,469
  • 7
  • 52
  • 66
Anthony
  • 7
  • 4

2 Answers2

0

In this case you want a .each() and use this where needed inside to get an attribute from the current element for usage, like this:

$('.ckeip_edit').each(function() {
  $(this).ckeip({
    data: {
      name : 'value',
      id : this.id
    },
    //options...
  });
});
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • Thank you very much, I have been banging my head on the desk for ages trying to get this to work. This has solved my problem entirely. :-) – Anthony Sep 22 '10 at 01:46
0

That won't work because this refers to the data object. You need to save the jQuery object so you can use it inside the object later.

Try something like:

var textarea = $('.ckeip_edit');

textarea.ckeip({
  data: {
    name : 'value',
    id : textarea[0].id;
  }
});
Cristian Sanchez
  • 31,171
  • 11
  • 57
  • 63