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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript "Please Wait.." Function Question

    Hi, I'm having some issues turning this "Please Wait"/Disabled button into a function.

    Code:
    <input type="submit" value="Submit Form" onClick="this.disabled = 'true'; this.value='Please wait...';" />
    Code:
    function pleasewait()
    {
    this.disabled = 'true';
    this.value='Please wait..'
    }
    
    <input type="submit" value="Submit Form" onClick="pleasewait();" />
    Thanks much

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    <script type = "text/javascript">
    function pleasewait(which) {
    which.disabled = true;
    which.value = 'Please wait..'
    }
    </script>
    <input type="submit" value="Submit Form" onClick="pleasewait(this);" />

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweet thanks so much Philip!

    Sorry if I'm getting too off the subject but I'm having a problem integrating this with my form validator. When I click the button, not matter whether the form validation is returned true or not the button says "Please wait.." and is disabled.

    Code:
    function validate_required(field,alerttxt)
    {
    with (field)
      {
      if (value==null||value=="")
        {
        alert(alerttxt);return false;
        }
      else
        {
        return true;
        }
      }
    }
    
    function validate_form(thisform)
    {
    with (thisform)
      {
      if (validate_required(email,"Email must be filled out!")==false)
      {email.focus();return false;}
      }
    }
    Mucho appreciated!!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Well, yes, What did you expect? Click button > run function.

    You must show how the validation function is being called in you <form ...... onsubmit = "whatever()" ....> code.

    You should note that form validation of the pattern if (value==null||value=="") is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. Numeric values, such as zip codes and phone numbers, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry.....

    The function is called like:

    Code:
    <form action="" name="form" onsubmit="return validate_form(this);">

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    There is no point in disabling the submit button or changing its value as submitting the form refreshes the page, restoring the original value.

    Code:
    <form name= "myform" onsubmit = "return validate()">
    <input type="submit" name = "subButton" value="Submit Form" />
    </form>
    
    <script type = "text/javascript">
    function validate () {
    document.myform.subButton.disabled = true;
    document.myform.subButton.value='Please wait..'
    alert ("Delay to show effect of form submission")
    return true;
    }
    
    </script>

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would it be plausible to add this javascript call after the form has been submitted then?

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by theflyingminstr View Post
    Would it be plausible to add this javascript call after the form has been submitted then?
    No. Of course not. Submitting the form refreshes the page and starts over - as my example has demonstrated.

    In any case, what is the user supposed to wait for? Godot? And what will cause that wait to end?
    Last edited by Philip M; 11-24-2010 at 05:54 PM.

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, understood. Thanks so much for clearing that up!


  •  

    Posting Permissions

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