Input onkeypress check if value emtpy - any ideas?

Posted on 2008-06-17
Last Modified: 2013-11-05
Hi All,

I need some Javascript code to allow an input "search" to constantly check it the value is empty onkeyup and if so fire an action.


<form id="searchform" name="searchform">
<input name="search" id="search" onkeyup="ACTION HERE">

For the purposes of this if someone could provide a full source snippet so that when using the input on keyup the input checks if the input box is empty and fires a message saying "empty" or similar.

I can then take it from there.

Thanks in advance for all help given.

Question by:spiroosx
LVL 49

Accepted Solution

Roonaan earned 500 total points
ID: 21801148

<script type="text/javascript">
function checkEmpty(field) {
  if(field.value.length < 1) {

Author Closing Comment

ID: 31467897
That's great! Thank you for your help.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery get each value 2 30
Java script read and write file - save as location 8 42
Window.Open() is showing a blank page 9 30 11 46
In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now