Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Validation for register input form

    Im trying to validate my input forms for a registration page. To do this I'm using js and xml response. In my xml response I link to a php page which echo's a value which should be the response value. The php page works perfectly. This is the js code:

    Code:
        function search(username)
    {
    var xmlhttp, answer;
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
    alert("Sorry, your browser seems to not support XMLHTTP functionality.");
    }
    
    
    xmlhttp.onreadystatechange=function()
    {
    if(xmlhttp.readyState==4)
    {
    answer=xmlhttp.responseText;
    if(compare_strings(answer,1))
    {
    document.getElementById("nameInfo").className="error";
    document.getElementById("username").className="error";
    document.getElementById("nameInfo").innerHTML="Please enter your desired username.";
    }
    else if(compare_strings(answer,2))
    {
    document.getElementById("nameInfo").className="error";
    document.getElementById("username").className="error";
    document.getElementById("nameInfo").innerHTML="The username <strong>"+username+"    </strong> is not allowed.";
    
    }
    else if(compare_strings(answer,3))
    {
    document.getElementById("nameInfo").className="error";
    document.getElementById("username").className="error";
    document.getElementById("nameInfo").innerHTML="The username <strong>"+username+"    </strong> has already been taken.";
    
    }
    else
    {
    document.getElementById("nameInfo").className="success";
    document.getElementById("username").className="";
    document.getElementById("nameInfo").innerHTML="Username <strong>"+username+"</strong>     is available.";
    flag=1;
    
    }
    }
    }
    var url="ajax_search.php";
    url=url+"?q="+username;
    url=url+"&sid="+Math.random();
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    /*It has been assumed here that ajax_search.php is in the same directory.*/
    xmlhttp.send(null);
    }
    Any help is really appreciated, thanks!

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    Code:
    compare_strings(answer,3)
    maybe a legit javascript command, but I have never heard of it. Try just using
    Code:
    if(answer == 1)
    Evolution - The non-random survival of random variants.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •