Link to home
Start Free TrialLog in
Avatar of bparmelee
bparmelee

asked on

Reset Button Not Working

Why does nothing happen when I click on the reset button?  Also, is there a way to set focus back to the text box when a user clicks reset?

Here is the current code where reset is not working:

<form name="search" method="get" onsubmit="return testSearchValue(this)" action="search.html">
      <input type="hidden" name="page_number" value="1"/>
      <input type="text" name="user_input" size="30" style="height:24"/>
      <input type="image" border="0" src="images/go.gif" alt="Go!" width="37" height="24" align="top"/>
      <a href="javascript:document.search.user_input.reset()">
            <img src="images/reset.gif" alt="Reset" border="0" width="74" height="24" align="top"\>
      </a>
</form>

If have tried calling this javascript from onClick in the <a> above and nothing happens:

function resetSearch()
{
      document.search.user_input.reset();
      document.search.user_input.focus();
}

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Timbo87
Timbo87

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Timbo87
Timbo87

With that code you no longer need to call any external functions.
The reason your code above didn't work is because you can't "reset" a textbox. You have to set its value to nothing. It's also better to run JavaScript through an onClick rather than the javascript: protocol.
Avatar of bparmelee

ASKER

Very cool!  Thanks!