I'm trying to create a script that checks for duplicates after you hit the submit button. If it finds duplicates, it cancels the submission and displays the duplicates on the page. If there are no duplicates, it submits the form.

I can get all the PHP side of things to work but not the canceling of the submission or tracking whether the PHP file has returned any data. Here is my code:

HTML Code:
<form onsubmit="return CheckLeadDuplicates();" ....
var AJAXForms = false;
var LastField = null;
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
AJAXForms = new XMLHttpRequest();

function CheckLeadDuplicates() {

if (window.XMLHttpRequest) {
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
AJAXForms = new ActiveXObject("Microsoft.XMLHTTP");

AJAXForms.onreadystatechange = processChange;
AJAXForms.open("GET", "modules/leads/ajax-duplicates.php?op=ajax&company=" +document.lead.company.value);

function processChange() {
    if (AJAXForms.readyState == 4) {   

     var res = document.getElementById("duplicatescheck");

        if (AJAXForms.responseText) {
            res.innerHTML = AJAXForms.responseText;
            res.style.visibility = "visible";
            return false;
        } else {
            return true;