I have a problem with the page redirection function that is executed when accessed by the enter key. Basically, onkeypress = Enter, or when you click on search, the page should be redirected to a predefined URL and add the search string to the request.
Redirecting works if I manually click "Search", however, if I just got into it, it is not. I added a warning to make sure the search function is activated, but this document.location.href does not redirect the page. In FF4, it refreshes the page (but saves the search bar). In IE7, it closes the window.
[ edit ] It seems appropriate that I use this on the Sharepoint site. The code works fine outside of Sharepoint. [/ change ]
The example below simplifies what I implemented but recreates the problem.
<script type="text/javascript"> function mySearch() { var SearchString = document.getElementById("SearchBox").value; var url = "http://stackoverflow.com/search?q="+SearchString; alert(SearchString); document.location.href = url; } </script> <input id="SearchBox" onkeypress="if (event.keyCode == 13) mySearch();"/> <a id="SearchButton" href="javascript:mySearch();" />Search</a>
Does anyone help?
source share