• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 788
  • Last Modified:

Javascript OnKeyDown Event

Trying to build something here using the onkeydown event and it is not working.  Here is what I have.

<input type="text" name="search-textbox" id="search-textbox" onkeydown="if (event.keyCode == 13) searchfunc()">
<a href="#" onclick="searchfunc()"><img id="search-button" src="images/search.gif" alt="Go" width="46" height="46">

When I type something into the box and click the image link, it works fine, but if I type in the box and hit enter, it just refreshes the page.

Any help is appreciated.
Andy

0
afkhk
Asked:
afkhk
1 Solution
 
Albert Van HalenAnalyst developerCommented:
Return false in your searchfunc and make some small changes in the onclick event of the link and onkeydown event of the textbox
<script type="text/javascript">
function searchfunc() {
   // all your logic...
   return false;
}
</script>
<input type="text" name="search-textbox" id="search-textbox" onkeydown="if (event.keyCode == 13) return searchfunc()">
<a href="#" onclick="return searchfunc()"><img id="search-button" src="images/search.gif" alt="Go" width="46" height="46">

Open in new window

0
 
afkhkAuthor Commented:
Thanks that did the trick!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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