Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Input TextBox check problom

    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?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Code:
    <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>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Alot
    Solved my problom... superb code.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You're welcome!

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •