Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
Droopers #1
number formats
Hello,
I'm in the middle of putting together the form front end to go over a 3rd
party store, and they require me to pass a total $ amount with two deicmals.
How can I control the input or submission of the dollar amount to make sure
that it always has two zeros after the decimal, even if the user doesn't enter
them on their own?
I've seen some of the numerical functions, but as the page the values are
sumitted to are not my own, I can't figure out how to format the data prior to
processing. Can anyone help?
Droopers Guest
-
date formats
hi i am working with uk date formats (dd/mm/yy) however the server the site is hosted on is in the us(mm/dd/yy) format i am using the following... -
sort from the smallest number to the highest number
Hi Just say I want to sort the row by using the fifth column data as reference from the smallest the largest number, if using sort, It will give... -
What video formats
What external sources can I load into a Flash movie. by this I think I mean I produce 100 clips and want to create a movie with a place holder ... -
formats
Is it possible to use more than one format in a script? I am parsing a log file to STDOUT and would like to be able to write to two (or more)... -
Don't need these file formats! Please help!
I would like to keep the file formats I use (PSD, BMP, GIF, JPEG, & TIFF). How can I unload the others? I've gone through the progam files folders of... -
jdeline #2
Re: number formats
Try the DollarFormat() function. [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=p art_cfm.htm[/url]
jdeline Guest
-
Droopers #3
Re: number formats
Thanks. I've seen the numerical formats before, but my problem is trying to
format an input variable before it's submitted. If I had a middle page, I could
go dollarformat(form.variable), but what I want is something to control entry
at the <cfinput> level.
Is this possible?
Droopers Guest
-
mattw #4
Re: number formats
If you are using CF7, you can add an attribute to cfinput called 'mask'.
Something like, <cfinput ... mask="99999.99">
If you are not using CF7, then break out the javascript manual...
mattw Guest
-
Droopers #5
Re: number formats
Thanks Matt.
I am using CF 7 and have tried my hand at the mask feature, though here's
where my rookie greenesss comes in. The field I'm having the fun with is a
donations field, where people enter amounts ranging from $10 to (hopefully) the
thousands. When I use the mask, I have to specify the number of digits for the
donation amount. So if I wanted someone to donate $10,000.00, my mask would
look like: 99999.99. But if using that same form, someone wanted to donate $10,
they would need to input it 00010.00, which is not really an option. Am I using
the mask incorrectly?
Is there a way for me preserve the flexibility of the form, while having some
sort of input mask? Even if there is a way to add the additional zeros is some
hidden manner, that'd be good. Any other creative solutions, oh wise and all
knowing coldfusion community?
Appreciating the good help :)
Droopers Guest
-
mattw #6
Re: number formats
You're right, that won't work. So, on to javascript...
The following will put .00 in if it is not there.
<script language="JavaScript">
function fn_PutDecimals(myForm) {
var digits = myForm.myMoney.value.split(".");
if (digits.length < 2) {
myForm.myMoney.value = myForm.myMoney.value + ".00";
}
}
</script>
<form name="testfrm" onSubmit="fn_PutDecimals(this)" action="formjs.cfm">
Money: <input type="text" name="myMoney"><br><br>
<input type="submit" name="submit" value="submit">
</form>
mattw Guest
-
Dan Bracuk #7
Re: number formats
Why can't you have a transitional page?
Originally posted by: Droopers
Thanks. I've seen the numerical formats before, but my problem is trying to
format an input variable before it's submitted. If I had a transitional page
before the variables were submitted to the 3rd party, I could go
dollarformat(form.variable), but what I want is something to control entry at
the <cfinput> level.
Is this possible?
Dan Bracuk Guest
-
Droopers #8
Re: number formats
Thanks Matt, I'll give it a shot.
As for not using a transitional page, part of the reason is I wanted to learn
how to control the inputs at the form level, and as well, I wanted to avoid
creating a second page if the only purpose of that page was to validate the
format of a single input. Creating a whole page for something that small just
seemed wasteful. Being new at this whole CF thing, I'm more than willing to
hear why I'm wrong. Bring on the good code theory! :)
What reasons would you suggest for using a transitional page, Dan? Should I
avoid using javascript to protect my inputs? Other thoughts?
Droopers Guest
-
Dan Bracuk #9
Re: number formats
If a transitional page allows you to get the job done with less time and
effort, use it. That may or may not be the case here, it sort of depends on
what the 3rd party application is expecting.
If they are expecting things like
form.x=1
then a transitional page might entail more work. If they are expecting
x=1
then that is something else altogether.
Originally posted by: Droopers
What reasons would you suggest for using a transitional page, Dan? Should I
avoid using javascript to protect my inputs? Other thoughts?
Dan Bracuk Guest
-
dimaint #10
Re: number formats
I think one of the reasons why you don't want to use JavaScript to protect your
vars is because JS is a client-side language and you don't really have control
over it. Some people would hvae it turned off, though such cases are becoming
very rare. Howver, even if it is on, different browsers (and even different
versions of the same browsers) might treat JS code differently. I don't think
it would matter much in your case, as it is really simple situation, but this
is just a general observation for future references.
dimaint Guest
-
mattw #11
Re: number formats
dimaint is right, using javascript can yeild unexpected results. I think the
best way is to do both client-side (javascript) and server-side (transition
page) validation.
Use the javascript I gave you. But also set up a transition page to double
check the value. You can code this transition page such that if all the
validation is good (i.e., no errors in the data), automatically redirect to the
shopping cart action page.
You could get fancy and use the javascript to validate. If all is found to be
valid, you pass in a Hidden field that allows you to skip the transition page.
If the Hidden variable was unchanged by the javascript, run the server-side
validation.
Also, FYI, if you use cfform and its "required" attribute, it uses javascript.
CF just writes the script for you. CF7 validation allows both client-side and
server-side validation.
Matt
mattw Guest



Reply With Quote

