I have a script that a friend wrote for me to populate numerous form fields with a list of dates from a text file. It calls the script once, and populates all fields with a particular Class name.
This is fine, and works perfectly in Firefox, Chrome, Safari and IE10. However the field appears blank (does not populate) in IE7, 8 or 9.
Any help anyone can give would be much appreciated. The code I'm using is as follows:
<script type="text/javascript">
window.onload = function() {
// call function to get list of options (call ONCE only)
var dateOptions = getDateOptions();
// get all elements with class tstselect and set the content to dateoptions
var els = document.getElementsByClassName('tstselect') ;
for (var i=0; i<els.length; i++) {
if (els[i]) {
els[i].innerHTML = dateOptions;
}
}
};
function getDateOptions() {
var url = 'dates.txt?'+new Date().getTime()
var output = '' ;
var txt=false;
if (window.ActiveXObject){
try {
txt=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try {
txt=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert(e);
}
}
}
else if (window.XMLHttpRequest){
txt=new XMLHttpRequest();
}
else {
return false;
}
txt.onreadystatechange=function(){
if (txt.readyState==4&&(txt.status==200||window.location.href.indexOf("http")==-1)){
var mydates = txt.responseText.split('\n');
for (var i=0;i<mydates.length;i++){
if (mydates[i]) {
// build up text string with all the options
output += '<option value="' + mydates[i] + '">' + mydates[i] + '</option>' ;
}
}
}
}
txt.open('GET',url,false);
try {
txt.send(null);
}
catch (e){
}
return output;
}
</script>
An example of the script in action can be found at: http://bespokebakery.co.uk/mailorder-birthday.html
Thanks in advance!!