Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

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!
0
bparmelee
Asked:
bparmelee
  • 2
1 Solution
 
Timbo87Commented:
<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="#" onClick="document.forms['search'].elements['user_input'].value = '';document.forms['search'].elements['user_input'].focus();return false;">
          <img src="images/reset.gif" alt="Reset" border="0" width="74" height="24" align="top"\>
     </a>
</form>
0
 
Timbo87Commented:
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.
0
 
bparmeleeAuthor Commented:
Very cool!  Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now