Thursday, 19 September 2013

Enabling/Disabling a button after database query

Enabling/Disabling a button after database query

I want to disable or enable a button, depending on the result of a
database-query. But I don't know how. From an example, I managed to show a
text (id="error", depending on the result of the query, but enabling the
button (id="generate") does not work.
This is my JavaScript:
function checkSender(str)
{
if(str == "")
{
str=document.getElementById("senderinput").value;
}
str=str.toUpperCase();
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("error").innerHTML=xmlhttp.responseText;
if(xmlhttp.responseText == "Einsender existiert nicht.")
{
document.getElementById("generate").disabled = true;
}
else
{
document.getElementById("generate").disabled = false;
}
}
}
xmlhttp.open("GET","checkSender.php?s="+str,true);
xmlhttp.send();
}
The response from checkSender.php is either "Einsender existiert nicht."
or an empty string.
Any suggestions?
Thanks in advance!
Marco Frost

No comments:

Post a Comment