1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Javascript Timer Question

Discussion in 'HTML & JavaScript' started by haydenm92, Mar 14, 2011.

  1. haydenm92

    haydenm92 Junior Member

    Joined:
    Apr 24, 2008
    Messages:
    141
    Likes Received:
    40
    Occupation:
    Student/Blackhatting
    Location:
    Idaho
    Home Page:
    I'm trying to manipulate the following code so that the text will appear after X time, rather than when clicking the image. Does anyone know how to do this?

    Code:
    <html> 
    <head> 
    <title>Untitled Document</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <style type="text/css"> 
    <!-- 
    textarea { 
        border: thin dashed #0066FF; 
        scrollbars: no; 
    } 
    --> 
    </style> 
    <script language="JavaScript" type="text/JavaScript"> 
    function sendText(e, text) 
    { 
      e.value = text 
    } 
    </script> 
    </head> 
    <body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" bgcolor="#FFFFFF"> 
    <table width="29%" height="292" border="0" align="center" cellpadding="4" cellspacing="2"> 
      <tr>  
        <td width="100%" height="210" colspan="2" valign="top"> <div align="center"><img name="image" width="300" height="200" onClick="sendText(document.form1.taupdate, 'got it working I see... :)')"></div></td> 
      </tr> 
      <tr>  
        <td height="80" colspan="2" valign="top"><form name="form1" method="post" action=""> 
            <div align="center">  
              <textarea name="taupdate" cols="30" id="taupdate"></textarea> 
            </div> 
          </form></td> 
      </tr> 
    </table> 
    </body> 
    </html>  
     
  2. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    645
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    I have to write something b/c BHW is complaining my msg is too short. The relevant code is below.

    Code:
    setTimeout("sendText()",3000); // time in milliseconds... 3000 = 3s
    
     
  3. haydenm92

    haydenm92 Junior Member

    Joined:
    Apr 24, 2008
    Messages:
    141
    Likes Received:
    40
    Occupation:
    Student/Blackhatting
    Location:
    Idaho
    Home Page:
    Thank you :)
    Now, I'm sorry, I'm a bit of a fail when it comes to scripting.
    Could you tell me where to place that line of code ha?
     
  4. easyroms

    easyroms Newbie

    Joined:
    Nov 5, 2009
    Messages:
    15
    Likes Received:
    1
    Place it in your script tags (I slightly modified sirgold's code):
    Code:
    <script language="JavaScript" type="text/JavaScript"> 
    function sendText(e, text) 
    { 
      e.value = text 
    } 
    setTimeout(function(){
      sendText(document.form1.taupdate, 'got it working I see... :)');
    },3000); 
     </script> 
    
     
  5. haydenm92

    haydenm92 Junior Member

    Joined:
    Apr 24, 2008
    Messages:
    141
    Likes Received:
    40
    Occupation:
    Student/Blackhatting
    Location:
    Idaho
    Home Page:
    Thanks so much guys, it's working perfectly :)