1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

disable submit button for 4 seconds

Discussion in 'JavaScript' started by SedNaX, Feb 25, 2007.

  1. #1
    I want a submit button to be disabled for 4 seconds after the page begins to load... how do i do that? I don't have experience with javascript:(
     
    SedNaX, Feb 25, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    I've made a working example for you:
    
    <html>
    <head>
    <script type="text/javascript">
    function text_enable() 
    { 
      document.formname.textname.disabled=false; 
      document.formname.submitname.disabled=false; 
    }
    </script>
    </head>
    <body onLoad="window.setTimeout('text_enable()',4000);">
    
    <form method="get" name="formname" action="http://www.YourSite.com">
      <input type="text" name="textname" size="24" maxlength="255" value="testing value"/>
      <input type="submit" name="submitname" value="TEST" disabled="true"/>
    </form>
    </body>
    </html>
    
    Code (markup):
     
    ajsa52, Feb 25, 2007 IP
  3. av1

    av1 Active Member

    Messages:
    168
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    ajsa52, you are disabling it with html and enabling it with javascript, what about these visitors that dont have js enabled? is there a way to disable a button with js instead of the disabled=true attr?
     
    av1, Feb 25, 2007 IP
  4. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Well, with my previous example you're "forcing" the visitor to Enable javascript.
    I you want your button enabled for visitor with javascript disabled, you can use something like this:

    
    <html>
    <head>
    <script type="text/javascript">
    function form_enable() 
    { 
      document.formname.textname.disabled=false; 
      document.formname.submitname.disabled=false; 
    }
    function form_disable() 
    {
      document.formname.textname.disabled=true; 
      document.formname.submitname.disabled=true; 
    }
    </script>
    </head>
    <body onLoad="form_disable(); window.setTimeout('form_enable()',4000);">
    
    <form method="get" name="formname" action="http://www.YourSite.com">
      <input type="text" name="textname" size="24" maxlength="255" value="testing value"/>
      <input type="submit" name="submitname" value="TEST"/>
    </form>
    </body>
    </html>
    
    
    Code (markup):
     
    ajsa52, Feb 25, 2007 IP
    SedNaX likes this.
  5. SedNaX

    SedNaX Active Member

    Messages:
    1,326
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    90
    #5
    okay thanks alot :D will try it out now :)
     
    SedNaX, Feb 25, 2007 IP