I am faced with a issue as follows:
<input title="1" type="text" class="email">
<input title="2" type="text" class="email">
<input title="3" type="text" class="email">
Above is my html where I am trying to grab the emails of each input box and store it in an object with the title as key.
Here is what my JavaScript currently looks like
var emailObj = {};
$("input[class=email]").each(function() {
var id = $(this).attr("title");
var email = $(this).val()
emailObj[id] = email;
});
Currently console.log displays only the last value added to the object as shown below.
Object { 3="[email protected]"}
Where my expected result should be as show below
Object { 1="[email protected]", 2="[email protected]", 3="[email protected]"}
Could someone shed some light on this issue for me please?
Thank you for reading, Regards.
.serializeArray();and put the titles as names. you just need to take care on the serverside part coz its gonna be an array of{name: "", value: ""}