Javascript onClick erase text field value...

Discussion in 'JavaScript' started by jehzlau, May 9, 2007.

  1. #1
    Hi, how can I make a javascript that will erase a certain value in the text field after clicking it... Just like in this forums.. the username field has the username value.. after clicking it, it will be erase.. I know it's pretty easy, I just don't know how :(
     
    jehzlau, May 9, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Yes, it's easy: document.getElementById('YOUR_ELEMENT').value = '';

    Example:

    
    <html>	
    <body>
        <input id="c1" name="c1" maxlength="10" size="10" value=""/> 
        <button type="button" onclick="JavaScript: alert(document.getElementById('c1').value ); document.getElementById('c1').value = '';">Test</button>
    </body>
    </html>	
    
    Code (markup):
     
    ajsa52, May 9, 2007 IP
  3. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #3
    heya! thanks it works! hehehe.. im so stupid.. i should have viewed the source.. because i can see it, it's javascript. wahehehe :) thanks again! ^_^
     
    jehzlau, May 10, 2007 IP