Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Clear input value on page load

    Hi,
    I was hoping someone could help. I need to clear a text input value when my page loads. any idea how I could do this with js or jquery? I need to set it to blank as oppose to reset it. It can clear all inputs if its easier. thanks guys!
    Last edited by howie2009; 10-02-2012 at 02:20 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,206
    Thanks
    80
    Thanked 4,566 Times in 4,530 Posts
    ??? So then why give it a non-blank value in the first place?

    But yes, trivial.
    Code:
    <html>
    <body>
    <form id="theForm" ...>
        <input name="whatever" value="banana pudding" />
        ...
    </form>
    <script type="text/javascript">
    (
      function( )
      {
          var form = document.getElementById("theForm");
          form.whatever.value = "";
      }
    )( );
    </script>
    </body>
    </html>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •