user3548161
user3548161

Reputation: 119

Array difference and on change update value

I have two arrays from which i generate dynamic input fields into 2 different div like below .

So once the input fields are created the user can alter the value inside an input field in div one or div two . If you notice div one and div two can have the same input field in this case firstname with same value of "john".

How can i do a check to see if the value of firstname has changed in div one or div two ? If the value of firstname has changed in div one or div two which ever is current than I take its value to submission ,I may have more than one similar fieldset and i need to do this on all similar field sets

So I'll submit

var finaldata= {firstname:"abraham", lastname:"Doe" ,age:46, address:"newyork" ,mobile:"04126562356"} 
var arrayone = {firstName:"John", lastName:"Doe", age:46};
var arraytwo = {firstName:"John", address:"newyork",mobile:"04126562356"};

Then I will loop through arrayone and output its values into a div

<div id="arrayone_panel">
   <input type="text" name="firstname" value="John">
   <input type="text" name="lastname" value="Doe">
   <input type="text" name="age"  value="46">
</div>

And for arraytwo I will loop through and output its values into another div

<div id="arraytwo_panel">
   <input type="text" name="firstname" value="John">  
   <input type="text" name="address" value="newyork">
   <input type="text" name="mobile" value="04126562356">
</div>

Upvotes: 0

Views: 65

Answers (1)

Dij
Dij

Reputation: 9808

you can attach event listeners to the both inputs separately and then take value for submission from respective event handlers, something like this:

$("#arrayone_panel").on('input', "[name='firstname']",function({
    //code..

}))


$("#arraytwo_panel").on('input', "[name='firstname']",function({
    //code..

}))

Upvotes: 1

Related Questions