Solved

Input onkeypress check if value emtpy - any ideas?

Posted on 2008-06-17
2
277 Views
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.

e.g.

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

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.

Spiro
0
Comment
Question by:spiroosx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 21801148
onkeyup="checkEmpty(this)">

<script type="text/javascript">
function checkEmpty(field) {
  if(field.value.length < 1) {
     alert('empty');
  }
}
</script>
0
 

Author Closing Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

617 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