Welcome to Dream.In.Code
Click Here
Getting Help is Easy!

Join 117,613 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,975 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Checking for empty form field

 
Reply to this topicStart new topic

Checking for empty form field

chris.tkd
post 26 Jun, 2008 - 03:07 AM
Post #1


D.I.C Head

Group Icon
Joined: 26 Sep, 2006
Posts: 55



Dream Kudos: 25
My Contributions


Hi,

I was wondering how to correctly check for an empty form field, my code at the minute checks if the field is null, contains "" or " " and counts that as empty

CODE

var inputs=document.getElementsByName("emailInputs");
  for(var i=0; i<inputs.length; i++) {
    if(inputs[i].value!='' || inputs[i].value!=' ' || inputs[i].value!=null) {
      console.debug("VALUE IS NOT BLANK");
    }
  }


The forms are always empty and it still prints out the VALUE IS NOT BLANK text.
When i print out the value of the forms using console.debug it shows the value as nothing. I could probably check the length of the input text but i just want to know whats wrong with the above code if anyone has any ideas?

Thanks
Chris,
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 26 Jun, 2008 - 01:10 PM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,569



Thanked 62 times

Dream Kudos: 975
My Contributions


Right now your code will always print out that is it a Blank Value. This is because of what you are using for your if statement:

CODE
if(inputs[i].value!='' || inputs[i].value!=' ' || inputs[i].value!=null) {
      console.debug("VALUE IS NOT BLANK");
    }


Which says that if the inpyut value is NOT equal to '' (nothing) OR is NOT equal to " " (a space) Or is NOT equal to null it should output Value Is Not Blank.

WHat you need to do is use a check something like so:

CODE
if(inputs[i].value == '' || inputs[i].value == ' ' || inputs[i].value == null) {
      console.debug("VALUE IS NOT BLANK");
    }


Which I believe will check for what you are wanting.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 11:54PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month