Expand my Community achievements bar.

How to check the given field is totally BLANK?

Avatar

Level 8

Hello,

My requirement is as below,

if ( my_text_field_1 == BLANK){ 

my_text_field_2.rawValue = "Blank"

}

if( my_text_field_1 = null){

my_text_field_3.rawValue = "NULL"

}

1) Pls. let me know How can do Java script

for this BLANK? is it a single space like " " (single space)...........if so, if user enters 2 spaces or 3 or 4 spaces, wht happens in that case? still my code works? or will it not work bcz we put only one space? 

2) Pls. consolidated the above JavaScript in a best practice way

Thank you

4 Replies

Avatar

Level 10

Try the following code.

//Trim the field's rawValue to check for the blankness.

if(my_text_field_3.rawValue.replace(/^\s+|\s+$/g,"") == "")

     my_text_field_3.rawValue = "Blank";

if(my_text_field_3.rawValue == null)

     my_text_field_3.rawValue = "Null";

Thanks

Srini

Avatar

Level 8

Thank you.

Sorry i did not understood the 1st piece, pls. eloborate

//Trim the field's rawValue to check for the blankness.

if(my_text_field_3.rawValue.replace(/^\s+|\s+$/g,"") == "")

     my_text_field_3.rawValue = "Blank";

Avatar

Level 10

The first section of the code will do a trim on the field's rawValue..

Then it checks for emptyness ("").

Based on your question you are not sure whether the user has entered a value in it/ one space/ two spaces/ three spaces etc..So if you trim the field value, then all the spaces will be removed and then you can check the field's rawValue.

Hope this helps.

Thanks

Srini

Avatar

Level 8

1) So, jusy i need to COPY & PASTE the below code as is?

if(my_text_field_3.rawValue.replace(/^\s+|\s+$/g,"") == "")

2) Then, wht are these special characters at the end?

Thank you