Results 1 to 5 of 5

Thread: javascript for single click button

  1. #1
    Join Date
    Sep 2006
    Location
    Pakistan
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript for single click button

    hi every one


    i need a javasript that will allow user to click on the button once, after it it may disable the button.


    please help.

    thanks

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form>
      <input name="Button" type="button" onClick="this.disabled = 'true';" value="Press Me">
    </form>
    </body>
    </html>

  3. #3
    Join Date
    Sep 2006
    Location
    Pakistan
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks budd

    well i tried to disabled the submit button through onclick but i prevents my form from submition instead i worked this way and have made it

    <SCRIPT LANGUAGE="JavaScript">
    var submitcount=0;

    function checkFields()
    {
    if (submitcount == 0)
    {
    submitcount++;
    return true;
    }
    else
    {
    alert("This form has already been submitted. Thanks!");
    return false;
    }
    }
    </script>


    and...

    <html:form action="/someAction" onsubmit="return checkFields()">

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter
    <input ... onClick="this.disabled = 'true';" ...>
    Changing the attribute value to:

    &#160;&#160;this.disabled = 'false';

    would still disable the control.


    Quote Originally Posted by Jamal
    well i tried to disabled the submit button ...
    Don't. If the submission fails and the user needs to resubmit, the button may still be disabled when they use the Back button to return (this behaviour varies between browsers, but does occur).

    If multiple submissions breaks your server-side code, then that code is broken itself. Detect and deal with it properly on the server.

    Mike

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

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
  •