Solved

Reset Button Not Working

Posted on 2003-12-04
3
432 Views
Last Modified: 2010-04-09
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
Comment
Question by:bparmelee
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 500 total points
ID: 9879581
<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
 
LVL 15

Expert Comment

by:Timbo87
ID: 9879600
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
 

Author Comment

by:bparmelee
ID: 9879654
Very cool!  Thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now