Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 20th, 2011, 12:33 PM
pbrown pbrown is offline
Forum n00b
 
Join Date: Sep 2011
Posts: 5
Default % and $ rule

I have a template where a customer can enter an amount off for a coupon. It can be a dollar amount or a percent. So I am trying to create a rule that will superscript the % if a percent amount is entered or superscript the $ and cents if a dollar amount is entered. I need one rule that does both and I am struggling creating it. Does anybody have such a rule? Thanks.
Reply With Quote
  #2  
Old September 20th, 2011, 02:23 PM
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 869
Default Re: % and $ rule

Can you add a sample PDF showing the various formats you want to handle along with a data file to show how your data will be supplied?

If your field will contain either "1.99", ".99", or "20%", you could do something like:
Code:
var amount = Field(YOUR FIELD");
// convert cent-only values to ##˘ format
if (Left(amount,1) == ".") amount = Right(amount,2) + "˘";
// convert dollar values to $#.## format
else if (amount.indexOf("%") == -1) amount = "$" + amount;
// add superscripting for symbols
amount = amount.replace("$","<superscript>$</superscript>").replace("˘","<superscript>˘</superscript>").replace("%","<superscript>%</superscript>");
return amount;
Of course, this may not work if other values can be input (i.e. "$1.99", "$.99", "0.99", etc).
Reply With Quote
  #3  
Old September 20th, 2011, 02:44 PM
pbrown pbrown is offline
Forum n00b
 
Join Date: Sep 2011
Posts: 5
Default Re: % and $ rule

Thanks for the quick reply.
The rule works except for when someone adds their own $ sign. The rule as is will then have 2 $ signs. So is it possible to tweak this rule to remove the one entered?
Attached Images
File Type: jpg Screen shot 2011-09-20 at 4.36.24 PM.jpg (49.8 KB, 7 views)
Reply With Quote
  #4  
Old September 21st, 2011, 06:59 AM
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 869
Default Re: % and $ rule

Sure. Just add what's in red:
Code:
var amount = Field(YOUR FIELD").replace("$","");;
// convert cent-only values to ##˘ format
if (Left(amount,1) == ".") amount = Right(amount,2) + "˘";
// convert dollar values to $#.## format
else if (amount.indexOf("%") == -1) amount = "$" + amount;
// add superscripting for symbols
amount = amount.replace("$","<superscript>$</superscript>").replace("˘","<superscript>˘</superscript>").replace("%","<superscript>%</superscript>");
return amount;
Although you'll still have a problem if the end user is able to place a leading zero for a cents-only value (i.e. "0.49"). For this reason, when we create a portal, we usually limit the characters that can be typed in the field and then "clean up" the result before forwarding to FP.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:30 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.