Expand my Community achievements bar.

SOLVED

How do I determine which text fields contain data?

Avatar

Level 2

Although this is a sad testament to my programming skills, I have little shame since I only do this kind of thing perhaps once every two or three years.  I’m using FormCalc (mainly b/c I’m still learning Javascript and this form had already been written in FormCalc). 

Here is the problem:

I have three text fields (Textfield1, Textfield2, Textfield3). 

I created three variables (var1, var2, var3) and initialized them to 0.

In order to determine how many of the fields contain data, I used if/then/else statements:

if (Textfield1.rawValue == “”) then

     var1 =0

else

     var1=1

endif

Textfield2 and Textfield3 have similar statements (using variables var2 and var3 respectively).

To test the code, I have a message box returning the sum of var1 + var2 + var3.  With NOTHING entered into any of the text fields, I would expect it to return a sum of 0, but it returns a sum of 3!  If I enter data into just one or two of the fields, again it returns a value of 3!

I’ve tried initializing the value of the Textfields (Textfield1.rawValue=””), but I still keep getting a value of 3. 

It's probably a simple programming error, but again I'm not a developer.  Any help would be appreciated.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I think you may need to change your code to: (replace the '' with null). Change from FormCalc to Javascript

if (Textfield1.rawValue == null) then

     var1 =0

else

     var1=1

endif

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

I think you may need to change your code to: (replace the '' with null). Change from FormCalc to Javascript

if (Textfield1.rawValue == null) then

     var1 =0

else

     var1=1

endif

Avatar

Level 2

Yep!  That works for me!  Thanks!

The entire form was done in FormCalc.  It would take too long (and beyond what I know of Javascript) to change it at this point.

Thanks again.

Avatar

Level 10

Just an FYI - you can mix and match FormCalc and JavaScript, even on the same object, just not on the same event.

Many of my forms have both, FormCalc makes some things a lot easier to do.

Avatar

Level 2

THAT is something I was not aware of and is quite helpful!!!  Thanks, Jono!!!

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----