AJAX Question

Hey there how is it going I got a question

Go on this site: http://www.w3schools.com/php/php_ajax_database.asp

This is a great tutorial but I am concerned with somethings I see.


 var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 } 
var url="getuser.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

  1. In this javascript code is it possible to have it display a loading image when the user presses submit, then right after it loads then the loading image disappears?
<html>
<head>
<script src="selectuser.js"></script>
</head>
<body>

<form> 
Select a User:
<select name="users" onchange="showUser(this.value)">
<option value="Peter">Peter Griffin</option>
<option value="Lois">Lois Griffin</option>
<option value="Glenn">Glenn Quagmire</option>
<option value="Joseph">Joseph Swanson</option>
</select>
</form>

<p>
<div id="txtHint"><b>User info will be listed here.</b></div>
</p>

</body>
</html>
  1. In the HTML Form, you’ll notice that there is only one List/Menu field. Is it possible to have multiple text fields and retrieve the entered data in the PHP page?? And how can I include a Submit button so if the user clicks on submit then the AJAX event takes place. I know there maybe some changes I may need to do on the javascript code.

I really hope somebody can reply back to this topic, I am in need to know this desperately so I can create some stunning web applications.