Hi, I'm developing a web application and one of the features is an autosave that automatically submits whatever data the form currently holds. It does it silently in the background while the user is still working on the form and they get notified through a message saying "Last AutoSave at: (time)". This is working fine with Firefox and Opera, yet not Internet Explorer. This is the code: <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var num = 0; function auto_save() { num++; sub(state); window.setTimeout("auto_save()", 30000); } </script> <body onload="auto_save()"> Code (markup): That is basically running the auto save every 30 seconds. The function being called each time is called sub with the argument being the form name (state) The sub function is part of a JS file called ajax.js This is the contents of ajax.js: var xmlReq = null; // Get the XML HTTP request depending on the browser function getXML(file,str) { var doc = null; if (window.ActiveXObject) { doc = new ActiveXObject("Microsoft.XMLHTTP"); doc.onreadystatechange = displayState; } else { doc = new XMLHttpRequest(); doc.onload = displayState; } doc.open( "POST", file, true ); doc.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); doc.send(str); return doc; } // Get all the form values from the specified form function getFormValues(fobj) { var str = ""; for(var i = 0;i < fobj.elements.length;i++) { switch(fobj.elements[i].type) { case "text": case "textarea": case "password": if (!fobj.elements[i].disabled) { str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].value) + "&"; } break; case "hidden": //hidden cannot be disabled str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].value) + "&"; break; case "checkbox": case "radio": if(fobj.elements[i].checked && !fobj.elements[i].disabled) { str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].value) + "&"; } break; case "select-one": if (!fobj.elements[i].disabled) { str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].options[fobj.elements[i].selectedIndex].value) + "&"; } break; case "select-multiple": if (!fobj.elements[i].disabled) { for (var j = 0; j < fobj.elements[i].length; j++) { var optElem = fobj.elements[i].options[j]; if (optElem.selected === true) { str += fobj.elements[i].name + "[]" + "=" + encodeURIComponent(optElem.value) + "&"; } } } break; } } //Strip final & str = str.substr(0,(str.length - 1)); return str; } // Output result to browser function displayState() { var res = document.getElementById("last_auto"); var now = new Date(); var hour = now.getHours(); var mins = now.getMinutes(); var secs = now.getSeconds(); res.innerHTML = "Last AutoSave at: <strong>"+hour+": "+mins+": "+secs+"</strong>"; res.style.visibility = "visible"; } // Gather everything together and submit it function sub(f) { var file = 'auto_save.php'; var str = getFormValues(f,"validate"); xmlReq = getXML(file,str); } Code (markup): Is there anything you can spot that will make it not work with IE? If you need any further information from me, just ask. Thanks in advance.
Replace: if (!fobj.elements.disabled) { str += fobj.elements.name + "=" + encodeURIComponent(fobj.elements.options[fobj.elements.selectedIndex].value) + "&"; } With: if (!fobj.elements.disabled) { str += fobj.elements.name + "=" + encodeURIComponent(fobj.elements.options[fobj.elements.selectedIndex].text) + "&"; } IE doesn't use value for the selectedindex...it uses text.