I need to submit a Collection (set, list, array) with objects that consists of:
id, phoneNumber, phoneType
I have a bunch of divs, here's some example HTML:
<div id="f9" class="facilityBox">
<div style="float:left;">
<label>BRANCH</label>
</div>
<div style="float:right;"> <a href="#" onclick="return Location.submitUpdateFacility(9)'">Save changes</a>
</div>
<div class="phoneSet">
<input type="text" value="787-788-1111" class="phones" name="number" />
<select class="phoneType" name="type">
<option selected="selected" value="PHONE">Phone</option>
<option value="FAX">Fax</option>
</select>
<input type="hidden" value="6" class="phoneId" name="id" />
</div>
<div class="phoneSet">
<input type="text" value="787-795-4095" class="phones" name="number" />
<select class="phoneType" name="type">
<option value="PHONE">Phone</option>
<option selected="selected" value="FAX">Fax</option>
</select>
<input type="hidden" value="106" class="phoneId" name="id" />
</div>
</div>
This div's id will be f+identifier, so for now it's f9
the js I have so far is:
Location.submitUpdateFacility = function (facilityId) {
$("#updateFacility input[name=index]").val(facilityId);
var id = facilityId;
var phones;
$("#" + id + " .phoneSet").each(function () {
phones += {
id: $(".phoneId input[name=id]").val(),
phoneNumber: $(".phones input[name=number]").val(),
phoneType: $(".phoneType select[name=type]").selected().val()
};
});
};
My problem is upon Firebug/Chrome console debugging, it does not go into the loop and thus no array is ever created. What am I doing wrong?
.each(function (index, element) {});?#f9 .phoneSetwhich should be every div with class phoneSet under div with id f9, I'm not convinced this would make any difference. Furthermore I have no need for the index anywhere, so yea. I'm not particularly sure what element does though.