I have an app where i have a javascript function called on an html select (onchange). Depending on what is selected it sends some output to a div; or it erases the output to that div. within the js function it builds the output into a js variable. and that variable is what is outputted. this has been working fine and I had some conditional inputs that would be loaded onto a form (the form beginning and end is outside of the div)
So where i am having the problem is where i try and put an input that has a class of "datepicker" on it. The jquery is not working on that input. And if i take the exact same input with that class outside of the js output variable it works fine.
here is me building the js output var in the js functon:
output253="This type of news item requires a start and end date...";
output253+="<br/><br/>";
output253+="<h3>Start Date</h3>";
output253+="<input type='date' name='start_date' />";
output253+="<h3>End Date</h3>";
output253+="<input type='date' name='end_date' />";
output253+="<br/><br/>";
output253+="<h3>Start99</h3>";
output253+="<input type='text' id='add-start-date' class='form-control datepicker' name='start99' />";
so i am sure it has something to do with the way i am doing this and things are not being interpreted properly because of how i am doing this; so I am trying to find out if there is a way to include this in the output variable where it will be able to interpret the jquery properly and load the datepicker on that output
Thanks!
adding entire code upon request
<select class="form-control" onchange="getValue1()" id="select_id253" name="type_id" required>
<option value="">Choose...</option>
{% for type in news_types %}
<option value="{{ type.id }}"{% if news.type_id == type.id %} selected{% endif %}>{{ type.name }}</option>
{% endfor %}
</select>
<p></p>
</div>
</div>
<script>
function getValue1() {
d = document.getElementById("select_id253").value;
var output253="";
if (d==='4' || d==='6') {
output253="This type of news item requires a start and end date...";
output253+="<br/><br/>";
output253+="<h3>Start Date</h3>";
output253+="<input type='date' name='start_date' />";
output253+="<h3>End Date</h3>";
output253+="<input type='date' name='end_date' />";
output253+="<br/><br/>";
output253+="<h3>Start99</h3>";
output253+="<input type='text' id='add-start-date' class='form-control datepicker' name='start99' />";
}
else {
output253="";
}
document.getElementById("gdemo253").innerHTML = output253;
}
</script>
<div id="gdemo253" style="padding: 20px;"></div>
<br />