<html>
<head>
<script type="text/javascript">
<!--
var xmlhttp;
function showUser(objEvt, objForm){
// Eingegebenen Benutzername auslesen
var str = objForm.elements['user'].value;
// Eventobjekt bestimmen
objEvt = (window.event)? window.event : objEvt;
// Defaultereignis (submit) abbrechen
if(typeof objEvt.preventDefault == "function"){
objEvt.preventDefault();
}else{
objEvt.returnValue = false;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null){
alert ("Browser does not support HTTP Request");
return;
}
var url="getuser.php";
url=url+"?user="+str;
url=url+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
// Callback-Funktion über anonyme Funktion aufrufen
xmlhttp.onreadystatechange = function(){
stateChanged(objForm);
}
xmlhttp.send(null);
}
function stateChanged(objF){
if (xmlhttp.readyState==4){
// Falls der Name noch frei ist -> Formular senden
if(xmlhttp.responseText.search(/Frei/i)!= -1){
objF.submit();
}else{
document.getElementById("txtHint").innerHTML = "Status Benutzername: " + xmlhttp.responseText;
}
}
}
function GetXmlHttpObject(){
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
//-->
</script>
</head>
<body>
<form action="formdata.php" method="post" onsubmit="showUser(event, this);">
<input name="user">
<input type="submit">
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>