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
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Show submit button when username is avaliable

    One more thing, how would I do it so it enables the submit button once the message is Avaliable username.

    I have this code:

    PHP Code:
     <script type="text/javascript">
      
    //function to create ajax object
      
    function pullAjax(){
        var 
    a;
        try{
          
    a=new XMLHttpRequest()
        }
        catch(
    b)
        {
          try
          {
            
    a=new ActiveXObject("Msxml2.XMLHTTP")
          }catch(
    b)
          {
            try
            {
              
    a=new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch(
    b)
            {
              
    alert("Your browser broke!");return false
            
    }
          }
        }
        return 
    a;
      }
     
      function 
    validate()
      {
        
    site_root '';
        var 
    document.getElementById('uname');
        var 
    msg document.getElementById('msg');
        var 
    submituser document.getElementById('submituser');
        
    user x.value;
     
        
    code '';
        
    message '';
        
    obj=pullAjax();
        
    obj.onreadystatechange=function()
        {
          if(
    obj.readyState==4)
          {
            eval(
    "result = "+obj.responseText);
            
    code result['code'];
            
    message result['result'];
     
            if(
    code <=0)
            {
              
    x.style.border "1px solid red";
              
    msg.style.color "red";
            
            }
            else
            {
              
    x.style.border "1px solid #000";
              
    msg.style.color "green";
              
    usersubmit.style.display 'block';
            }
            
    msg.innerHTML message;
          }
        }
        
    obj.open("GET",site_root+"js/user_availability.php?username="+user,true);
        
    obj.send(null);
      }
    </script> 
    and the form is here:
    PHP Code:
    echo "<form action='' method='POST'>";
        echo 
    '
        User Name : 
        <input type="text" onblur="validate();" id="uname" name="uname" value="" />
    <div id="msg"></div>'
    ;

        echo 
    "next info";         

        echo 
    "<input name='step3' value='Next' id='submituser' style='display:none' type='submit' />";
        echo 
    "</form>"
    I set it as display none as a default and then when the box is green for the box to show as a block.

    Its not showing up tho after the box becomes green
    MY MSN: Sith717@Hotmail.com
    PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
    PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Ready to kick yourself?
    Code:
        var submituser = document.getElementById('submituser');
        ...    
          usersubmit.style.display = 'block';
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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