SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast mitsy's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jquery form field clear

    i think this will help people a lot, cuz i couldn't find any simple answer by googling 3 hours...
    i need a very very simple jquery form field reset.
    here is the picture what i need:

    HTML Code:
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.min.js'></script>
    
    <script>
    function reset_field() {
    $('searchbox').val()=''
    }
    </script>
    
    <form id='form'>
    <input id='searchbox' type='text' name='q'>
    </form>
    <a href="#" onclick="call the resetting function">this link should clear the input field above</a>


    this is what i need, of course the above example does not work. i just need the correct syntax for defining the reset function and correct syntax for how to call the function by a text link.

    please help me, i know this issue will be so simple
    but i just couldnt solve this problem

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Just checking, but did you know there is a native html input attribute for that? You can just use

    Code:
    <input type="reset">
    within your form to provide a reset button for all fields. Apologies if you were looking for something different.

  3. #3
    SitePoint Enthusiast mitsy's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have discovered the error
    $('searchbox').val()=''
    should be
    $('#searchbox').val()=''
    only # sign missing lol


Tags for this Thread

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
  •