• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

testing if input field is empty onblur

Hi,

when a user clicks into an input field, onblur, I want to test if that field has been left blank.  Currently, I have tried
if (strString == "") but it doesn't work.  does anyone know the correct syntax to use?

Thanks

Mitesh
0
mitesh114
Asked:
mitesh114
1 Solution
 
BatalfCommented:
You can test it like this:

<script>
function testField(obj){    // "obj" is a reference to the text field
    if(obj.value.length==0){    // Length of value in text field is 0
        alert('No value selected');
    }

}
</script>

with an onblur event like this:

<input type="text" onblur="testField(this)" name="whatever">

"this" is a reference to this text field.
0
 
mitesh114Author Commented:
thanks Batalf,

The problem was that just above my code, I had:
if (strString.length == 0) return false; which was preventing me from testing an empty string.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now