Setting the value of an object through Jquery Each()

Friday, July 11, 2014

I'm attempting to iterate through an object.key (newPickup) and set the value of object.key equal to the value specified in a form. I can get through to the end without throwing any errors however, when i call the object all items are undefined. I set up a fiddle with it already loaded and I'm hoping one of you talented magnificos can let me know where I messed up. Thanks in advance.


<button id="startPickup">Schedule Pickup</button>
<div id="pickupWrap"></div>

function Pickup(pickupDate, clinicName, phoneNumber, qtySpec, fedexConfirm){
this.pickupDate = pickupDate;
this.clinicName = clinicName;
this.phoneNumber = phoneNumber;
this.qtySpec = qtySpec;
//The Pickup Object
var newPickup = new Pickup();

//Click the button to make the form
//Empty if exists
//Make the inputs
$.each(newPickup, function(key,value){
$('#pickupWrap').append("<label for=\""+key+"\">"+key+": </label><input type=\"text\" id=\""+key+"\" class=\"pickupInput\"><br>");
//Make the button
$('#pickupWrap').append("<button id='submitPickup'>Submit Pickup</button");

//Capture the form inputs from pickup

//Get Values and Indexes
var pickupIndex = $(this).attr("id");
var pickupValue =$(this).val();

console.log(pickupIndex+" | "+ pickupValue);

//Set newPickup to appropriate value
$.each(newPickup, function(key, value){
if (key === pickupIndex) {
console.log("we have a match");
value = pickupValue;