Saturday, July 27, 2019

Updated text fields to JSON string - Javascript/JQuery

I have a dynamic form that has text fields which change to input boxes when they need to be updated.



When they have been updated and the user clicks submit I want to add the updated values to a json string which i can post to an ASP.NET script.



Here is the html of 2 rows in the table:




Colleague 1:
















Del







Colleague 2:















Del






Here is the jQuery I'm using to detect which input boxes have been updated:



$("#subdetails").click(function () {
$("#mantab input[type=text]").each(function () {
if ($(this).val() !== this.defaultValue) {

//code to create json string


}
});
});


This is an example of a json string i would like to create if the following field were updated:



{
"1":{
"c1nametb": "newname",

"c1exttb": "22227",
}
"2":{
"c2eaddtb": "neweadd@company.co.uk",
"c2pnotb": "0111122210",
}
}


Can any one please help me with the code to create this string, or advise on a better way of doing this?




Thanks
Ryan

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...