Need help disabling a submit button onClick

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poml
    New Member
    • Feb 2008
    • 5

    Need help disabling a submit button onClick

    Hello, first time posting on thescripts.com, and I'm in dire need of some help.
    All I want to do is disable the submit button (not the entire form) onClick, and am wondering if this is possible.

    Here's the current coding:
    [CODE=HTML]<form enctype="multip art/form-data" action="?id=com pleteupload" name="submitfor m" method="POST">
    <b>File to Upload:</b>&nbsp;<input name="userfile" size="50" type="file"><br ><br>
    <span class="class3">
    <input type="checkbox" name="agree" value="22">I agree to the upload terms and conditions for mysite.com (<a href='agreement .php' target='_blank' >&nbsp;View Terms&nbsp;</a>)<br><br>
    <input type="submit" value="Upload File" name="uploadbut ton" onclick="submit form.disabled=t rue; submitform.form .submit();">
    </font></span>
    </form>[/CODE]

    It's a file upload script, everything works other then when i try to disable the button onclick. With this current coding in IE it disables the entire form and doesn't process the request. FireFox it processes the request, but doesn't disable the button or form.

    If anybody can help it would be greatly appreciated, thanks.
    Last edited by eWish; Feb 27 '08, 01:55 AM. Reason: Please use [CODE][/CODE] tags
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    If you are wanting to do away with the JavaScript function 'onclick', then simply delete the code for it.

    [CODE=JavaScript]onclick="submit form.disabled=t rue; submitform.form .submit();"[/CODE]

    --Kevin

    Comment

    • poml
      New Member
      • Feb 2008
      • 5

      #3
      Thanks for the quick reply ewish, still not working. I'm kind of new to this coding.

      i found a new code of disabling the button onClick

      onclick="docume nt.submitform.s ubmitbutton.dis abled=true;
      document.submit form.mode.name = 'post';
      document.submit form.onsubmit() ;
      document.submit form.submit();"

      Cool thing is is this works just fine in firefox, disables the button and then processes upload.php to upload the selected file. Only problem is in IE it just disables the button and doesn't process upload.php.

      Comment

      • eWish
        Recognized Expert Contributor
        • Jul 2007
        • 973

        #4
        I guess that I don't understand. Do you want the data from the form to be sent to your php script? If so, would that not require the submit button? If not, then what is the purpose of the submit button in the first place? How else will you know that the user is done filling out the form and ready for processing if you don't use the button?

        --Kevin

        Comment

        • poml
          New Member
          • Feb 2008
          • 5

          #5
          Here, ...

          If you try it in IE, the button is just disabled and it doesn't process

          If you try it in FireFox, it disables it and uploads the file just fine

          All I want is it for the submit button to be disabled in firefox and ie and goto the upload.php script. As far is checking the filesize, terms of agreement, all that works fine. If the user has inputed a valid file and accepted the terms of agreement, i just want Upload File submit button to be disabled to prevent anxious users from constantly clicking it.

          Sorry for the confusion, I'm not good with explaining things.

          Comment

          • drhowarddrfine
            Recognized Expert Expert
            • Sep 2006
            • 7434

            #6
            You'll get better javascript answers from the javascript forum. I'll send this there.

            Comment

            • poml
              New Member
              • Feb 2008
              • 5

              #7
              No need, I finally figured it out. Thank you very much though, this can get mighty frustrating at times. I appreciate it.

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Originally posted by poml
                No need, I finally figured it out. Thank you very much though, this can get mighty frustrating at times. I appreciate it.
                Do you want to share your solution with our members in this forum? Thanks.

                Ronald

                Comment

                • poml
                  New Member
                  • Feb 2008
                  • 5

                  #9
                  Originally posted by ronverdonk
                  Do you want to share your solution with our members in this forum? Thanks.

                  Ronald
                  Definately, onClick this disables the Submit button within a Form and changes the caption to 'One Moment Please...' (works in IE and FireFox)

                  [HTML]<form enctype="multip art/form-data" action="upload. php" name="submitfor m" id="submitform " method="POST">
                  <b>File to Upload:</b>&nbsp;<input name="userfile" size="50" type="file"><br ><br>
                  <input type="submit" value="Upload" name="submitbut ton" onclick="docume nt.submitform.s ubmitbutton.val ue='One Moment Please...'; document.submit form.submitbutt on.disabled=tru e; document.submit form.submit();" >
                  </form>[/HTML]
                  Last edited by acoder; Mar 2 '08, 01:33 PM. Reason: Added code tags

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by poml
                    Definately, onClick this disables the Submit button within a Form and changes the caption to 'One Moment Please...' (works in IE and FireFox)
                    Thanks for posting your solution, but please remember to use code tags when posting code. Thanks!

                    Comment

                    Working...