jquery - How to get and replace data from form serialize() before submitting? -
i need submit form using jquery before it's submitted want change value of 1 of form fields without showing change user. know it's not best way software demands that.
currently use:
var submit = $("#submitform").serialize(); to serialize data , submit them using
$.post('/post', submit) the serialized data have are:
entry%5bbody%5d=hello+and+welcome&addedcontexts=presentation&context=prese ntation&selectedcontexts=&statementid=×tamp=
i want change value of entry%5bbody%5d else.
i know use regex on string (i can't find which?), maybe know of more elegant solution? such first serializing form, deserializing it, changing value need, , serializing again?
thanks!
use $("#submitform").serializearray() , search item in array name property equal "entry[body]" , edit value property.
// convert form data array var data = $("#submitform").serializearray(); // edit data here // using es6 data.find(item => item.name === 'entry[body]').value = "something else"; // or using es5 data.foreach(function (item) { if (item.name === 'entry[body]') { item.value = "something else"; } }); // post $.post('/post', $.param(data));
Comments
Post a Comment