Many thanks if you are looking at this.
I have a simple order form that allows users to place an order for an item. The form also allows the user to add more items, calling a javascript function that utilizes innerhtml.
Included in each order form, are dates. I am using a jquery calendar to populate the dates.
When the original form is loaded, the calendar works fine, but when I call the function to add items via the innerhtml, the calendar does not work, either on the original form text fields, or the form text fields added by the innerhtml function.
When the form loads for the first time I have, wrapped in a div with id=image_details, 2 form fields, below:
<div><label>Collection Date:</label></div>
<div><input type="text" name="1_colct" id="date" class="required"/></div>
<div><label>Delivery Date:</label></div>
<div><input type="text" name="1_dlvr" id="datea" class="required"/></div>
<div><a href='#' onclick='addInput()'>Add Another Parcel</a></div>
When the form text field is clicked it calls the following jquery to display an interactive calendar
$(function() {
$("#date").datepicker({ showOtherMonths: true });
$("#datea").datepicker({ showOtherMonths: true });
$("#date"+newnumber+"").datepicker({ showOtherMonths: true });
$("#datea"+newnumber+"").datepicker({ showOtherMonths: true });
});
every is fine up to this point
If I select Add Another Parcel, this calls javascript function addInput, below (note I'm using the newnumber variable to prefix name and id to create unique values that will be used later).
function addInput() {
var number=2;
var newnumber = number+fields;
document.getElementById('image_details').innerHTML += "<div><label>Collection Date:</label></div><div><input type='text' name='"+newnumber+"_colct' id='date"+newnumber"' class='required'/></div><div><label>Delivery Date:</label></div><div><input type='text' name='"+newnumber+"_dlvr' id='datea"+newnumber"' class='required'/></div>";
fields += 1;
}
This is where it all goes wrong.
I cannot call the calendar from the original id="date" or id="datea" (as I could before)
and the html added via innerhtml will not allow me to call the calendar from id='date"+newnumber"' or id='datea"+newnumber"'
Also, as it seems that the innerhtml function does not output the html in the conventional way, therefore I cannot use the view source function of the browser to assist in the debug.
Can anyone help?