tags:

views:

53

answers:

3

hi

function liveUpdate(fld,value,id) {

    $.ajax({
      type: 'POST',
      url: 'myurl.html',
      data: { fld:value, 'id': id },
      success: function(data){//console.log(data);
      }
    });

    }

i want fld to be posted as fld's value not the variable name fld? i've tried to wrap around with eval but no luck

any ideas?

thanks

A: 

you need to modify the following line.

data: { fld:fld, id: id },
Adeel
doesnt work.. the value of fld that i am passing to the funciton is eg. product_name (can be different), value is 'toaster' i want it so when i post (goign to a Coldfusion script) i have a variable called product_name = toasterand not fld = toaster.. i can update the server side code if not possible, but prefer not to..
Alessandro
+1  A: 

You could do something like this:

function liveUpdate(fld, value, id) {
    var data={id: id};
    data[fld]=value;
    $.ajax({
        type: "POST",
        url: "myurl.html",
        data: data,
        success: function(data) {
            //console.log(data);
        }
    });
}
icktoofay
A: 
var data = { id : id };
data[fld] = value;

$.ajax({ ..., data : data });
deceze
this worked. thanks heaps
Alessandro