Skip to main content
Inspiring
March 11, 2019
Answered

Convert Form result to a number

  • March 11, 2019
  • 1 reply
  • 1097 views

Hello,

I need to take the value submitted in a form and add 99 to it. I first tried:

<cfset channel.type = 'Form[P#c#Channel]' + 99>

That failed since the form value is a string not a number.

Then I tried:

<cfset channel.type = LSParseNumber('Form[P#c#Channel]') + 99> and got

Form[P1Channel] must be interpretable as a valid number in the current locale.

How can I change the submitted value to a number that I can perform addition on?

Thanks!

Gary

    This topic has been closed for replies.
    Correct answer WolfShade

    Maybe this will help. I dumped the form values.


    Wait a minnit.. are you using 'channel' as a struct or array???  That might be the culprit.  It makes no sense for CF to think '5' is a scalar variable, but it could think 'channel' is a string, not a struct or array.

    V/r,

    ^ _ ^

    1 reply

    WolfShade
    Legend
    March 11, 2019

    <cfset channel.type = INT(form['P#c#Channel']) + 99 />

    Part of the issue is that you are placing form within the quote, which is what not to do.    Form needs to be outside the string delimiter so that CF knows you're trying to access a value in the form scope.

    HTH,

    ^ _ ^

    ghanna1Author
    Inspiring
    March 11, 2019

    Thank you!

    ghanna1Author
    Inspiring
    March 11, 2019

    I probably should have tested it first...(before marking as correct)

    <cfset channel.type = INT(form['P#c#Channel']) + 99 />

    That returns:

    You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.