Hi sorry I am very new to AJAX and javascript probably a silly question but where can I put
document.getElementById("loading").innerHTML='loading...';
in the following so it appears when it is loading and disappears when it is loaded?
function getstate(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("Please Activate Javascript in your browser to continue.");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if (xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("tempresult").value=xmlHttp.responseText;
var stateval;
var stateval = document.getElementById("tempresult").value;
var stateval = stateval.trim();
if (stateval=="nostates")
{
document.getElementById('staterow').style.visibility='hidden';
document.getElementById('cityrow').style.visibility='hidden';
document.getElementById('postalrow').style.visibility='hidden';
getcitybycc();
}
else
{
document.getElementById('staterow').style.visibility='visible';
document.getElementById('stateinput').innerHTML=xmlHttp.responseText;
document.getElementById('cityrow').style.visibility='hidden';
document.getElementById('postalrow').style.visibility='hidden';
}
}
}
}
var url="submitsignup.php";
document.getElementById("tempresult").innerHTML='';
document.getElementById('staterow').style.visibility='hidden';
document.getElementById('cityrow').style.visibility='hidden';
document.getElementById('postalrow').style.visibility='hidden';
var country;
var country = document.getElementById("country");
var getstate;
var getstate = 'getstate';
var params = "country="+country.value+"&getstate="+getstate;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send(params);
}