• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Empty Text Box keeps inserting value

Contributor ,
Nov 14, 2007 Nov 14, 2007

Copy link to clipboard

Copied

I have a form with many optional fields, and I have my SQL update statement updating the database correctly when radio and checkboxes are selected. However, when it comes to text boxes, I can't seem to get my update statement to "skip" them if there is no value. The fields in the statment below that are text boxes are the ScanCount and DestroyManDate.

TOPICS
Advanced techniques

Views

482

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 14, 2007 Nov 14, 2007
Lucky Kitty wrote:
What am I missing?

That you are testing the length of the string "DestroyManDate" not the
value of a variable of that name, i.e NO QUOTES. I also usually use
trim incase somebody inputs just whitespace characters.

<cfif Len(Trim(destroyManDate)) GT 0>....</cfif>



Votes

Translate

Translate
LEGEND ,
Nov 14, 2007 Nov 14, 2007

Copy link to clipboard

Copied

Text boxes will always have a value, even if it's an empty string. Trim the value and either check that the result is not an empty string or that it's length is > 0.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 14, 2007 Nov 14, 2007

Copy link to clipboard

Copied

....and you really don't need the is True after IsDefined().

Phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 14, 2007 Nov 14, 2007

Copy link to clipboard

Copied

I changed that line of code to <cfif len("DestroyManDate")GT 0>DestroyManDate = '#Trim(DestroyManDate)#',</cfif> but it still inserts a value from the text box. What am I missing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2007 Nov 14, 2007

Copy link to clipboard

Copied

Lucky Kitty wrote:
What am I missing?

That you are testing the length of the string "DestroyManDate" not the
value of a variable of that name, i.e NO QUOTES. I also usually use
trim incase somebody inputs just whitespace characters.

<cfif Len(Trim(destroyManDate)) GT 0>....</cfif>



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 14, 2007 Nov 14, 2007

Copy link to clipboard

Copied

LATEST
> <cfif len("DestroyManDate")GT 0>

That checks the length of the literal string "DestroyManDate", not the value of a variable or form field. You probably mean :

<cfif len(DestroyManDate) GT 0>

Though you should trim() and scope your variables.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation