Results 1 to 5 of 5

Thread: RE-Enable form button if authentication fails after disabling?

  1. #1
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default RE-Enable form button if authentication fails after disabling?

    I'm disbaling a submit button on submit and validating some info. I'm trying to enable it again if the user fails authentication to re-enter data. Here is my code. Seems to work in Safari, IE but not Mozilla.

    Code:
    <script language="javascript">
    function submitform()
    {
    if (document.getElementById("code").value != "4343")
    {
    window.alert("incorrect code. try again.");
    document.getElementById("btnsubmit").value = "Send Feedback";
    document.getElementById("btnsubmit").disabled = false;
    return false;
    }
    else
    {
    document.form1.submit();
    }
    }
    </script>
    
    <input type="button" name="btnsubmit" id="btnsubmit" value="Send Feedback" onClick="this.value='Please wait...';this.disabled = true;submitform();"/>
    it worked once, then when I rechecked it, the button stays disabled after a failed authentication? I hate when that happens because I implement the code all over!

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Replace:
    Code:
    onClick="this.value='Please wait...';this.disabled = true;submitform();"
    With:
    Code:
    onClick="submitform(this);"
    And change your javascript to:
    Code:
    function submitform(me) {
      if (document.getElementById("code").value != "4343") {
        window.alert("incorrect code. try again.");
        me.value = "Send Feedback";
        if(me.disabled) {
          me.disabled = false;
        }
        return false;
      } else {
    document.form1.submit();
      }
    }
    Jeremy | jfein.net

  3. #3
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    If I remove:

    Code:
    onClick="this.value='Please wait...';this.disabled = true;submitform();"
    then even my original code works actually.

    I wanted to disable the submit button upon submit and display a please wait message. The part I wanted was to return the button back to its original state if the user fails the authentication statements.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Nile View Post
    Replace:
    Code:
    onClick="this.value='Please wait...';this.disabled = true;submitform();"
    With:
    Code:
    onClick="submitform(this);"
    Please read my whole post. When you call the submitform function, it will make the value please wait, and disable it.
    Jeremy | jfein.net

  5. #5
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Here's an example. Only Mozilla gives me trouble. The button is not reenabled after hitting OK in the alert:
    http://monaya.bravehost.com/javascri...ablebutton.htm

Bookmarks

Posting Permissions

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