...

View Full Version : Input TextBox check problom



JsHelp
08-27-2007, 01:40 PM
http://www.forever.co.il/Problom.htm

Look at the source code...
i did, onkeydown.. check if Enter Key was pressed && TextBox != empty. if so, submit the form, else -> alert('TextBox Is Empty');

However, from some reason it alert every letter i press... (which is not Enter Key even thou it is suppose to trigger only on Enter Key).

Can anyone correct my mistake?

nikkiH
08-27-2007, 02:50 PM
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Js Problom</title>
<script>
function foo(frm)
{
if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
{
// enter key was pressed
if (frm.Sname.value == "")
{
alert('Empty Text Box');
return false;
}
else
{
frm.submit();
}
}
}
</script>
</head>
<body>
<form method="get" id="SearchBox" name="SearchBox" action="">
<p align="center">
<input type="text" name="Sname" size="20" dir="rtl" onkeydown="return foo(this.form)">
<br>
<input type="image" src="http://www.forever.co.il/SearchButton.jpg" name="Search" value="Submit" width="66" height="24">
</p>
</form>
</body>
</html>

JsHelp
08-27-2007, 06:39 PM
Thanks Alot :)
Solved my problom... superb code.

nikkiH
08-27-2007, 06:53 PM
You're welcome!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum