I am trying to loop through all input=text fields that have a specific class and extract the value of the input fields using jQuery. I can't seam to get the value though as no matter what, it gives me "(an empty string)" in the console.
How can I get the value? My code is:
$.each($('.datepicker'), function() {
console.log(this);
console.log($(this).val());
});
The output of this is:
<input id="createdDate" class="datepicker hasDatepicker" type="text" onchange="setDueDate();" value="2013-06-19" size="8" name="invoice[createdDate]">
(an empty string)
<input id="dueDate" class="datepicker hasDatepicker" type="text" value="2013-06-19" size="8" name="invoice[dueDate]">
(an empty string)
Edit: It seams the issue was part cached JS (even though the file was showing correctly in the source, it was executing the older JS...very odd), and part the jQuery datepicker screwing things up. I fixed it like so:
$(document).ready(function() {
$('.datepicker').datepicker();
$.each($('.datepicker'), function() {
date = $(this).val();
$(this).datepicker('option', 'dateFormat', 'yy-mm-dd');
$(this).datepicker('setDate', date);
});
});