Good day to all, I'm new to jQuery. I have this code.
$(document).ready(function() {
var start_date = '';
var end_date = '';
var total = 0;
$("#getdate").click(function () {
start_date = parseInt($('#startdate').val().substring(5,7));
end_date = parseInt($('#enddate').val().substring(5,7));
total = (end_date - start_date) + 1;
var monthDiv = $(document.createElement('div')).attr("id",'month' + total);
for(i=1;i<=total;i++){
monthDiv.after().html('<input type="text" />');
monthDiv.appendTo("#monthList");
}
//alert(total);
});
});
Don't know where I went wrong but.. I want to generate textboxes base on the dates (start_date and end_date) so for example in the input type date I start with January and ends with March it should generate 3 textboxes. But in my code, it seems it will only generate one textbox per click. Any help would be much appreciated. Thanks!
And here's my html code:
<html>
<body>
<input type="date" id="startdate" name="start_date" />
<input type="date" id="enddate" name="end_date" />
<input type="button" id="getdate" value="GET DATE"/>
<div id="monthList">
</div>
</body>
</html>
monthDiv.append('<input type="text" />');instead ofmonthDiv.after().html('<input type="text" />');$('<div />')instead of$(document.createElement('div'))