Results 1 to 11 of 11

Thread: [RESOLVED] How to disable button

  1. #1

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

    Resolved [RESOLVED] How to disable button

    Hi
    I want to disable button when I click it.
    How can I do it in PHP?

    Thanks

  2. #2
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: How to disable button

    It's best done with Javascript.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to disable button

    Yes as the PHP won't run until the form is submitted and the page reloaded.

    Use the JS "disabled" property.

  4. #4

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

    Re: How to disable button

    OK
    How can I do it in JavaScript?

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to disable button

    You can use the onclick event in Javascript:
    Code:
    onclick="this.setAttribute('disabled', 'disabled');"
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to disable button

    There is also the newer way which is to use DOM event listeners. Since IE as usual has its own way of doing things I've made wrapper functions for these. Download the file and then reference it to your page using a <script> element in your <head> section (don't reference my URL, apart from nicking my bandwidth I might delete or move that file yet). Use addEHandler() to add a click event once the window has loaded.

    HTML Code:
    <!-- ... -->
    <head>
      <script type="text/javascript" src="event-listeners.js"></script>
    </head>
    
    <!-- ... -->
    
    <button id="myButton">Click me</button>
    Javascript:
    Code:
    addEHandler(window, 'load', doOnload);
    
    function doOnload()
    {
      addEHandler(document.getElementById('myButton', 'click', doBtnClick));
    }
    
    function doBtnClick(e)
    {
      var obj = e.target || e.srcElement;
      obj.setAttribute('disabled', 'disabled');
    }
    While on the face of it it's a ton more code, it has the advantage of not polluting your HTML markup with Javascript code, thus keeping it neat and content-centric. This principle should be followed for CSS styling as well. Always have your CSS in an external stylesheet (for non-trivial pages) or a <style> block in the <head> section (for trivial pages). Seperating content from presentation and scripting also means you can easily update each bit individually.

    Information overload? Probably. But that's web design for you. If you take the easy way, we'll all have crap websites

  7. #7

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

    Re: [RESOLVED] How to disable button

    Thanks very much

  8. #8

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

    Re: [RESOLVED] How to disable button

    OK
    There's something else.
    How can I add JS code above to HTML Editor (e.g. Front Page)?

  9. #9
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: [RESOLVED] How to disable button

    go into code view and paste it in. make sure ou put the top one in the head section and the rest in your body code

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] How to disable button

    FrontPage is an airborne piece of flaming bovine excrement. Please do not ever use it to make a page that's going to on the WWW.

    I recommend Notepad++.

  11. #11
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [RESOLVED] How to disable button

    NotePad or NoteMe, potato, potaato, Frontpage is depricated as of 2006. they will come out with a totaly new application soon. But untill we have computers that can translate wrong to right Emacs is the way to go..


    - ØØ -

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