Code: Select all
<SCRIPT language="JScript" type="text/javascript">
function IsEmpty( in_string ) {
if( in_string.length == 0 || in_string == null ) return true;
else return false;
}
function ValidateForm()
{
if( IsEmpty( document.forms["name"].a.value ) ) {
alert( 'enter at least 1 word' );
return false;
}
if( ( document.forms["name"].a.value ) == "search" ) {
return false;
}
document.forms["name"].submit();
return true;
}
</script>
<form method="post" name="name" id="name">
<input name="a" id="a" type="text" value="search" onclick="if (value=='search') value=''";>
<input type="button" name="buton" value="search" onclick="ValidateForm();">
</form>
it works as intended as long as the button is clicked. If the user just presses "enter" the form is submited even if it is empty.
how can I prevent the "enter" button on the keyboard to submit the form?