Use an XML RPC call to talk to your database.
For clarity I use a synchronous call in the example below, as indicated by the false parameter to rpc.open().
function checkform()
{
var name = $.trim($("#acname").val());
if (name.length == 0){
alert("Please Enter Name");
$("#acname").focus();
return false;
}
// Ask the database. The 'http://host/check_name_in_db.php' must be a PHP script
// that can handle receiving an HTTP POST with a parameter named 'name'. It then
// has to determine if the name passed in exists or not and return an answer.
// The answer can be in any format you'd like, many people use XML or JSON for this.
// For this example, I just assume that your PHP script will return (echo, print,
// printf()) the strings 'yes' or 'no' as a response to whether or not the name was
// found in the database.
var params='name='+name;
var rpc = new XMLHttpRequest();
rpc.open('POST', 'http://host/check_name_in_db.php', false);
rpc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
rpc.send(params);
// Wait until the RPC request is complete.
// This is somewhat dangerous as an RPC call _can_ be aborted for example.
// That could cause your javascript to hang here.
while (rpc.readyState != 4) {};
var reply = rpc.responseText;
// Your PHP script wrote 'yes' back to us, which would mean that the name was
// found in the database.
if (reply == 'yes')
{
return true;
}
else
{
return false;
}
}