When the user wants to search, I check if the textbox is empty and also validate its way by clicking on the "search" button, or by validating the "enter" key.
After the user performs a search with a keyword (found or not found) the 1st time, it tries to validate the text field blank validating the enter key (not clicking on the search button), there is one error message but the page is reloaded! For now, I do a little checking in PHP to determine if the field is empty, so the user gets the message "Please enter your search." on the page.
My question is: why the page is reloaded it by validating the enter key while the field is empty? Should I completely prohibit the use of the enter key? (a little too simple for my liking!)
Here is my simplified code:
HTML Code:
<script type="text/javascript">
<!--
function controle()
{
if(document.formsearch.input.value!='')
{
document.formsearch.action = "index-search.html";
document.formsearch.submit();
}
else
{
alert("Not work!" );
}
}
-->
</script>
</head>
<body>
<form name="formsearch" method="post">
<input name="input" id="input" type="text" size="30" onKeyPress="if(event.keyCode == 13) controle();"/>
<input class="button" type="button" name="test" value="Search" onClick="controle();"></form>
</body>
</html>
Bookmarks