Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: changing element value after serialized

If i have my form elements with values in variable data (contains: var data = $(this).serializeArray();)

How can i do change the value of an form element (called recipient), when it's inside data?

So my element with name=recipient have value "mama", how can I change it to "papa" on ajax success

like image 979
Johnson Avatar asked Apr 30 '26 06:04

Johnson


2 Answers

You can iterate through your objects in the array, change the object's value:

for (var item in data)
{
  if (data[item].name == 'recipient') {
    data[item].value = 'papa';
  }
}
like image 75
Ricardo Rodrigues Avatar answered May 02 '26 20:05

Ricardo Rodrigues


$.each(data, function(key, data)
{
    if (this.name == "recipient") 
        this.value="papa";
});
like image 38
muhammad800804 Avatar answered May 02 '26 20:05

muhammad800804



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!