disable submit button

Discussion in 'JavaScript' started by bumbar, Sep 1, 2008.

  1. #1
    Hallo!

    Is it possible for the button for the sending only to be activated if the all fields to be completed?

    I think that must be used
    getElementById['Login'].disable=true
    HTML:
    But it is not obviously how... :(

    Here the code:

    
    <script type="text/javascript">
      
          function check()
      
          {
      
              if(document.getElementById("username").value=="")
      
              {
      
                  alert("Please, type username!");
      				return false        
      
              }
      
              if(document.getElementById("password").value=="")
              {
                  alert("Please, type password!");
             		return false
              }
      
          } 
          </script>
      
            <form id="form1" name="form1" method="post" action="" onsubmit="return check()"> 
              <label> Username: 
              <input type="text" name="username" id="username" />  
              <br />
              Password:  
              <input type="text" name="password" id="password" />  
             <br /> 
              <input type="submit" name="Login" id="Login" value="Submit" />  
              </label> 
            </form>
    
    HTML:
    Thanx!
     
    bumbar, Sep 1, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have to return true if the input is correct. Just add a "return true;" at the end of check()
     
    xlcho, Sep 1, 2008 IP
  3. vasago

    vasago Peon

    Messages:
    95
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi, Bumbar,

    the property you need is disableD :)
    Just add one "d" at the end;
    Like this:

    getElementById['Login'].disabled=true;
     
    vasago, Sep 1, 2008 IP
  4. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I totally missed the 'disabled' problem :eek: vasago is right about the property name, but i wonder why would you need to disable the button when your check() function is working just fine for stoping the form from submition (you just need to add 'return true' as i said before)...
     
    xlcho, Sep 1, 2008 IP