Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data in empty textfield

Status
Not open for further replies.

tomvdduin

Programmer
Sep 29, 2002
155
NL
I want to test a textfield if it is not empty. i tried:
!=''
!=null
!= '0'
!=0

but when a textfield is empty, all the above is false.

How can I test a textfield if it is not empty?
 
myText = document.myForm.textField.value

if (myText == ""){
alert("The field is empty")
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
mwolf00,

I appreciate your reaction, but that doesn't work either.

I have the following:
if (this.document.form_abonnement.ABO_SRE_PK_DEB.value!="")
{
blabla
}

that's the correct syntax, right?

I also alerted the value of the textbox, and there is noting printed on the alertbox.
 
You do understand that what you have posted will evaluate true only if something IS inside the textbox, right? Since you are checking (texfield != ""), blabla is executed only if there is something in the textfield. If you want blabla to be executed only when the textfield is blank, change your if statement to this:
Code:
if (document.form_abonnement.ABO_SRE_PK_DEB.value == "")


-kaht

banghead.gif
 
Your syntax is correct. Since you get the blank alert message, your spelling must be correct too. Check to make sure your text field doesn't accidentally have a blank space in it.

It might be helpful if we saw more code (the whole JS function and the HTML surrounding the text field).

--Dave
 
You may have spaces in the input box...

try this
Code:
<script>
function LTrim(strValue){
  var LTRIMrgExp = /^\s */;
  return strValue.replace(LTRIMrgExp, '');
}
function RTrim(strValue){
  var RTRIMrgExp = /\s *$/;
  return strValue.replace(RTRIMrgExp, '');
}

function checkVal(){
  myText = LTrim(RTrim(document.myForm.textField.value))
  if (myText != ""){
    //add your code here
  }
}

</script>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Hmm, ok when I use:
if (this.document.form_abonnement.ABO_SRE_PK_DEB.value==""), it works correctly.

It is part of a larger piece of code, and because of the complexity, I did it wrong.

stupid me...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top