Results 1 to 10 of 10

Thread: How to Disable submit button

  1. #1
    Join Date
    May 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to Disable submit button

    Hi,

    I've a test.php page with submit button and the process/display also in the same page(test.php).So,my question is how to disable submit button after submission test.php.I mean submit button in the test.php disable after the submission not during the submission....any idea???

    Regards
    Khairul

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Please post a link to the page on your site that contains the problem so we can check it out.



    The "process/display" is?


    after the submission not during the submission
    huh?


    I think you're asking how to disable sending the form twice.... making sure they don't just keep clicking submit.

    I'm not sure how this would work.

    but, since you're using php, you could just have a check before doing your action.

    1. Store the submissions somewhere (or even just the one last one)
    2. Check when submitted if that data matches the old data (and IP address)
    3. If it does, end, do nothing (already submitted... no big deal), if not do your normal action.


    I'm not sure what "disable" is in javascript, but you could do it this way:
    either onSubmit in the <form> tag, or onClick on the submit button....

    You could set that to a function.

    the function could set a variable to 1 and submit the form.
    The fuction, when clicked again, would see that it already equals 1, and not do anything.
    if != 1, var = 1, submit. else (do nothing, probably or alert('only submit once.'))
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi....
    Thanks for the reply...
    Anyway...process and display is in the same page that is test.php.to be clear...from test.php --->submit--->process-->display--->test.php...so all is one page.
    so i wondering if there is javascript that can disable the submit button after the submission i mean at the test.php for display part

    Regards
    Khairul

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok.

    So... is the "process/display" php or javascript based?

    You could submit the page to itself, have php run through the $_GET or POST variables, then do stuff.
    Or you could have a javascript action attached to submit that does stuff with the values in the form.

    Either way, I still say make an onSubmit="function()", where function() checks if var == 1. If not, it makes it equal 1, and does your action. If it DOES equal 1, then it does nothing. This is basically turning on a switch the first time it's submitted then not allowing it again.
    There MAY also be a disable function for a button. I don't know about this. Try googling it. But, make it work would be easy... just onClick="thatfunction" Or, maybe onSubmit for the form tag.


    And, again, I can't picture it.... Please link to your page!
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    May 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi...

    Sorry i couldnt post the link since is just using localhost....anyway the page of-course in php but i wanted to use javascript for disabling the submit button...yes i did googling about this problem....but the most of the solution are disable for multiple click/submission..mean the button disable during the submission/loading and the page submiited is not the same is different page....which is not what i want....

    Regards,
    Poyor7

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    document.forms['nameOfForm'].elements['nameOfSubmitButton'].disabled = true;
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    May 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi..
    Twey...

    Then in the html code what changes should i make?

    Regards
    Poyor7

  8. #8
    Join Date
    May 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi...

    Here i try to use Twey idea...it only disable button but not submitting at all..
    -------
    function SubmitTheForm()
    {
    document.forms['form'].elements['Submit'].disabled = true;
    }
    -------
    test.html page
    <form name="form" action="test.html">
    <input type="submit" name="Submit" value="Save" onclick="return SubmitTheForm();">
    <form>

    Regards,
    Poyor7

  9. #9
    Join Date
    May 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi...

    Based on this script....where how where should i put coding for disable button?example like twey coding....

    <SCRIPT LANGUAGE="JavaScript">

    function SubmitTheForm()
    {
    if (input.validation.value=="false")
    {
    input.validation.value="true";
    }
    else
    return false;
    }
    }
    </SCRIPT>
    <FORM name="form" action="test.html">
    <input type="submit" name="Submit" value="Save" onclick="return SubmitTheForm();">
    <input type="hidden" name="validation" value="false">
    </FORM>

    Regards,
    Poyor7

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <form action="test.html" onsubmit="
      if(!this.form.elements['validation'].value) return (this.form.elements['validation'].value = true);
      else return !(this.form.elements['Submit'].disabled = true);
    ">
      <input type="submit" name="Submit" value="Save">
      <input type="hidden" name="validation" value="">
    </form>
    I think that's right, but I'm not entirely sure what you're trying to do here.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •