Solved

Reset Button Not Working

Posted on 2003-12-04
3
440 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

777 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