Solved

Reset Button Not Working

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Return data with AJAX, JQUERY and PHP 13 56
Form not operating correctly. 1 23
Bootstrap on PLNKR 3 16
how to avoid redundand ajax calls 5 9
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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 code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

867 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

18 Experts available now in Live!

Get 1:1 Help Now