View Full Version : Input TextBox check problom

08-27-2007, 01:40 PM

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?

08-27-2007, 02:50 PM
<html dir="rtl">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Js Problom</title>
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;
<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)">
<input type="image" src="http://www.forever.co.il/SearchButton.jpg" name="Search" value="Submit" width="66" height="24">

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

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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum