Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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 ...
    4. 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)...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default 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

  8. #7

    Default 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

  9. #8

    Default 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

  10. #9

    Default 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

  11. #10

    Default 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

  12. #11

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139