Form Submit Button Unclickable Until All Fields Are Filled In??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    Form Submit Button Unclickable Until All Fields Are Filled In??

    I hope this is the right place for this question, I'm working on a site with HTML/CSS/PHP/AJAX and i have a form that i don't want the submit button to be 'enabled' or clickable until all the other fields in the form are filled??
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you could write a javascript that checks if all fields are filled before the submit is triggered.

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      some thing like:
      Code:
      formObj.onsubmit = function() {
          var ele = this.elements;
          for (var i = 0; i< ele.length; i++)
          if (!ele[i].value) return false;
          return true;
      }

      Comment

      • ziycon
        Contributor
        • Sep 2008
        • 384

        #4
        Ok, i can do that but how do get the submit button to enable itself once all fields are populated without refreshing the page?

        Comment

        • ziycon
          Contributor
          • Sep 2008
          • 384

          #5
          I have this so far:
          Code:
          <script language="javascript">
            function checkfields() {
              
            }
          </script>
          </head>
          <body>
          <form method="post" method="../signup/">
                    <input type="text" id="uname" name="uname" size="35" />
                       <select id="day" name="day">
                           <option value="0">dd</option>
                       </select>&nbsp;/&nbsp;
                       <select id="month" name="month">
                           <option value="0">mm</option>
                       </select>&nbsp;/&nbsp;
                       <select id="year" name="year">
                           <option value="0">yyyy</option>
                       </select>
               <input type="radio" id="gender" name="gender" value="male">&nbsp;male$nbsp;<input type="radio" name="gender" value="female">&nbsp;female
               <input type="submit" value="signup" onclick="checkfields(); return false;" />
          </form>
          Can you point me in the right direction?

          Comment

          • ziycon
            Contributor
            • Sep 2008
            • 384

            #6
            Got it sorted, found stuff on google(eventual ly), thanks for the help lads!

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              So what did you use in the end?

              If you had the submit button disabled, you could enable it when all fields are filled in by calling a function onblur of each element. Another option is to call the form submit() method. I would suggest that you disable the submit button onload via JavaScript so that users with JavaScript disabled will still be able to submit.

              Comment

              Working...