I want to push the Javascript object using a loop And Getting the value of input using jQuery.
var data = {name: "Grace"};
$("#test").on('change', function () {
console.log($('"#test'+1+'T"').val());
for(var i=1; i<= 2; i++){
data['Thomas'+i+'Shelby'] = $('"#test'+i+'T"').val();
}
console.log(data);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<input type="text" id="test1T">
<input type="text" id="test2T">
<input type="text" id="test">
Syntax error, unrecognized expression: "#test1T"
**Expected Output: **
If user input Arthur in #test1T, John in #test2T and Micheal in #test.
Then It should console log following object:
{
name: "Grace",
Thomas1Shelby: "Arthur",
Thomas2Shelby: "John",
}
Micheal?