Results 1 to 34 of 34

Thread: How to disable button in action

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    How to disable button in action

    Hello
    Take a look at this code
    PHP Code:
    <?php
    if ($v == "1") {
      --
    "ACTIONS WHICH I WANT TO DO"--
      exit();
    }

    echo 
    "<form action=file.php method=post>";
    echo 
    "<input type=hidden name=v value=1>";
    echo 
    "<input type=submit value=Go>";
    echo 
    "</form>";
    ?>
    What I want how can I disable the button "Go" after I'd clicked on it.
    I know it needs JS, how can I do it by JS?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    This is what you're looking for.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I saved it as "html" and it didn't work.
    After I'd clicked on the button, nothing happends.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    the script works fine, there's a demo on the site... if you didn't set it up correctly, then it isn't going to work. make sure you read the comments given to set it up correctly...
    Like Archer? Check out some Sterling Archer quotes.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I don't know how to program JS well.
    Can you set it up for me?

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    ..? there is no setting up.. all you need to do is read and follow the directions, you don't need to know javascript. all of the code is aleady given to you. there's nothing to change. if you have a submit button you will have a form that it is contained in. add the onSubmit parameter to that form, just like in the code given to you, and add the rest of the code at the top of your page.
    Like Archer? Check out some Sterling Archer quotes.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I pasted it in FrontPage, I saved it, I previewed it then I clicked on the submit button, nothing happends.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    I don't use FrontPage, and never have, so I don't know what you're doing wrong... post your code if you can't get it working :/
    Like Archer? Check out some Sterling Archer quotes.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I used that code which in the website, but I saved it as "html" file.

  10. #10
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    It doesn't matter if you saved it as an HTML file, that's what you're supposed to do. The code works fine, so if it isn't working in FrontPage for you, then I don't know what to tell you, because I don't use it and don't know what it might do.

    Try pasting it into Notepad and saving it as an HTML file and open it in IE.
    Like Archer? Check out some Sterling Archer quotes.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    But it couldn't show the message (alert).

  12. #12
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    if the demo on the site I gave you displayed the alert and your version didn't, then what did you change?

    if the demo on the site didn't display an alert, then you have an out-of-date browser.

    I checked, and the script works as expected in the latest versions of FireFox, IE7 Beta/IE6, and Opera.
    Like Archer? Check out some Sterling Archer quotes.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I have IE 6.0
    OK I don't want to show alert; I just want when I click on the submit button, the button disables and going to another website.

  14. #14
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    then just take the alerts out. the rest of the code will still work.
    Like Archer? Check out some Sterling Archer quotes.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I want to save it as PHP, look what I wrote:
    PHP Code:
    <?php
    echo "<form onSubmit=\"return disableForm(this);\">";
    echo 
    "Name: <input type=text name=person>";
    echo 
    "<input type=submit><input type=reset>";
    echo 
    "</form>";
    ?>

    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    function disableForm(theform) {
    if (document.all || document.getElementById) {
    for (i = 0; i < theform.length; i++) {
    var tempobj = theform.elements[i];
    if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
    tempobj.disabled = true;
    }
    document.write ($person);
    return true;
    }
    else {
    alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
    return false;

    </script>
    </head>
    </html>
    But it didn't work.
    It couldn't output $person.
    Why please?

  16. #16
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    .. you can't do that to output PHP. Writing PHP in plain text without telling the server to parse your code (using <?php/?> tags) won't do anything. You also have the order of your file incorrect.. the "<html>" and "<head>" tags should be at the start of the page, before any other previous output, and your form should be AFTER the JavaScript function you're using is defined. And, there's no reason for you to echo all of that form stuff using PHP if you're not doing anything with PHP in it. Furthermore, you didn't define $person so it won't output anything until you do so. You also deleted parts of the script you used that were needed for it to even run correctly... if you don't know the language you're working with and don't know what something does, you shouldn't just be removing it, unless it's to reverse engineer it.

    PHP Code:
    <html>
    <
    head>
    <
    SCRIPT LANGUAGE="JavaScript">
      function 
    disableForm(theform) {
        if (
    document.all || document.getElementById) {
          for (
    0theform.lengthi++) {
            var 
    tempobj theform.elements[i];
            if (
    tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset"tempobj.disabled true;
          }
          return 
    true;
        } else {
          return 
    false;
        }
      }
    </
    script>
    </
    head>
    <
    body>
    <
    form onSubmit="return disableForm(this);">
      
    Name: <input type=text name=person>
      <
    input type=submit><input type=reset>
    </
    form>
    </
    body>
    </
    html
    Like Archer? Check out some Sterling Archer quotes.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I want to do it by using PHP.
    I want to disable the submit button after I'd clicked on it by using PHP.

  18. #18
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    .. you can't do that with PHP. PHP is a server-side language, if you want something to change in PHP you must refresh the page, because the script is parsed at the server and sent to you. JavaScript is client-side, meaning that it is parsed by the browser when you're viewing it, allowing for dynamic things like the updating the time, or disabling a submit button like you want. what you want to use is JavaScript, not PHP, and there's no way you're going to get what you want without using it.. and the script I linked to you is exactly what you need. I even rearranged it all to basically do exactly what you want to do. what's your problem with it?

    You can still save it as .php (although, if you have no actual PHP code in it, that will be a little pointless), but it will not be doing anything dynamic until you put code in it to do so..
    Like Archer? Check out some Sterling Archer quotes.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I want to use JS in a PHP page.

  20. #20
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    so.. save it as a PHP file instead of an HTML file.. Javascript will work in any kind of HTML, whether it is contained in a PHP file or an HTML file.
    Like Archer? Check out some Sterling Archer quotes.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I couldn't do it, it isn't working.
    Can you do it and attach it as a file in this topic for me pleeeeeeeeeease?
    I'll be appreciated.

    Thanks

  22. #22
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    Why would I attach it as a file when I already posted the code you can use? I edited it for you to work the way you wanted it to.

    If you do not have JavaScript enabled, it will not work. Other than that, I don't know why it isn't working for you, but it's fine for me.
    Like Archer? Check out some Sterling Archer quotes.

  23. #23
    New Member
    Join Date
    Oct 2006
    Posts
    6

    Re: How to disable button in action

    Why don't you use php to disable your button ? I assume that u want your user to submit only once, then after that they can't click on the go button anymore, then you can do it without using js.

    PHP Code:
    <?php
    $flag 
    "";   // A flag to decide whether to disable the button or not

    if (isset($_POST)) {
        
    // Something was posted. Disable the button
        
    $flag "disabled";
    } else {
        
    // Nothing was posted. Enable the button
        
    $flag "";
    }
    ?>

    <input type="submit" value="Go" <?php echo $flag?>>
    Hope this helps...

  24. #24
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: How to disable button in action

    Because that's not the point. He wants to prevent double submit, which happens when the server takes a bit to respond and the user clicks the submit button again, on the same page.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I want to echo the value "$person", how?

  26. #26
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    using javascript?

    PHP Code:
    <script language="javascript">
      document.write("<?php echo $person?>");
    </script>
    Like Archer? Check out some Sterling Archer quotes.

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I want to echo it when I click on the submit button and I want the submit button to be disabled.

  28. #28
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: How to disable button in action

    Quote Originally Posted by kows
    using javascript?

    PHP Code:
    <script language="javascript">
      document.write("<?php echo $person?>");
    </script>
    You use PHP to generate JavaScript code that writes something during page creation?

    Why not just write it directly from PHP?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  29. #29
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    I have no clue, I figured he might want to do something else with it besides just output it to the browser.

    if you want to disable it and then echo that variable, just use the code I provided already in conjunction with the onClick attribute of the submit button.

    PHP Code:
    <input type="submit" onClick="return disableForm(this); document.write('<?php echo $person?>');" value="submit">
    Like Archer? Check out some Sterling Archer quotes.

  30. #30
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: How to disable button in action

    No, you can't use document.write() after the page has finished loading. You need a different way of DOM manipulation.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  31. #31
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    errgh, I forgot. you would just need to have a tag that was invisible on start (using CSS), and then make it visible with the onClick event. I haven't done anything in JavaScript for a long time, though, so I probably can't help you much. your best bet would probably be to go to the JavaScript forum. you can't do real-time stuff like that with just PHP.
    Like Archer? Check out some Sterling Archer quotes.

  32. #32

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    I want exacty when I click on submit button, it disables and begins to download file by using:
    header ("Location: http://www.mywebsite/file.zip")

  33. #33
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: How to disable button in action

    you have to make the page submit to another script to be able to send it a new header..
    Like Archer? Check out some Sterling Archer quotes.

  34. #34

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Location
    United States
    Posts
    157

    Re: How to disable button in action

    how?
    Sorry, but I have no idea about JS.
    Last edited by onh1986; Oct 16th, 2006 at 04:38 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width