Skip to main content
Inspiring
Mar 11, 2019 7:31 PM UTC
Answered

Convert Form result to a number

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 is closed to new replies. Start a new post to keep the conversation going.
    WolfShade
    WolfShadeCorrect answer
    Legend
    Mar 11, 2019 9:11 PM UTC

    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,

    ^ _ ^

    10 replies

    WolfShade
    Legend
    Mar 11, 2019 7:51 PM UTC

    <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,

    ^ _ ^

    Translate
    ghanna1Author
    Inspiring
    Mar 11, 2019 8:40 PM UTC

    Thank you!

    Translate
    ghanna1Author
    Inspiring
    Mar 11, 2019 8:44 PM UTC

    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.

    Translate