Copy link to clipboard
Copied
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
How can I change the submitted value to a number that I can perform addition on?
Thanks!
Gary
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,
^ _ ^
Copy link to clipboard
Copied
<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,
^ _ ^
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
I probably should have tested it first...(before marking as correct)
<cfset channel.type = INT(form['P#c#Channel']) + 99 />
That returns:
Copy link to clipboard
Copied
Ignore my last post. I hate the Jive platform!!! It's not letting me delete it. (I had to close the browser and re-logon to finally delete it.)
Try val() instead of int. Although the scalar error message confuses me. Are you sure that the form submits a single value?
V/r,
^ _ ^
Copy link to clipboard
Copied
Maybe this will help. I dumped the form values.
Copy link to clipboard
Copied
Very odd. Try LSParseNumber, again, with the quotes in the right place. If that doesn't work, I don't know.. I've never seen CF declare '5' as a scalar variable.
V/r,
^ _ ^
Copy link to clipboard
Copied
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,
^ _ ^
Copy link to clipboard
Copied
I changed channel.type to just channel and it works.
Copy link to clipboard
Copied
Glad to hear you got it fixed. And thank you for marking my answer as correct. I do appreciate it.
V/r,
^ _ ^
UPDATE: Actually, now that I think of it, if you declare channel a struct, THEN try to save it as "channel.type", that might work.
Copy link to clipboard
Copied
Try this:
<cfset channel = {} /> <!--- Implicit create --->
or
<cfset channel = StructNew() /> <!--- Expressed create --->
Then start working with your form scope.
<cfset channel.type = lsParseNumber(form['P#c#Channel']) + 99 />
HTH,
^ _ ^