uph printshop Posted September 16, 2013 Share Posted September 16, 2013 I am developing a thank you card where you can select a default message or enter your own custom message that appears on the inside of the card. The way I have it set up now, is I have a field named "message type" that is intended to be a drop-down menu with "default" and "custom" selections, and then I have a field named "custom message" where if "custom" is selected, you can type in your message. If default is selected, I want a generic thank you message to appear. Basically I want the coding to say if "default" is selected, return "default thank you message". If "custom" is selected, return the contents of the "custom message" field. Im just not sure how to set up the coding for this. Thank you! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 16, 2013 Share Posted September 16, 2013 if (Field("message type") == "default") return "default thank you message"; //else return Field("Custom Message"); Quote Link to comment Share on other sites More sharing options...
uph printshop Posted September 17, 2013 Author Share Posted September 17, 2013 That worked great, but i also need some text replaced in the return line. The code below is what I had before I added the If statement. They all worked, I just need to incorporate the ReplaceSubstrings into the If statement. var a = Field("custom text"); a = ReplaceSubstring(a, "=" , "<br />"); a = ReplaceSubstring(a, "&" , "&"); a = ReplaceSubstring(a, "\\" , "|"); return a; The code I have now is below. I could figure out how to incorporate one replacesubstring at a time. var a = Field("custom text") var b = "Custom Message Here"; if (Field("message type") == "custom") return ReplaceSubstring(a, "=", "<br />"); else if (Field("message type") == "default") return ReplaceSubstring(b, "=", "<br />"); Thanks so much for your help with this! Quote Link to comment Share on other sites More sharing options...
step Posted September 17, 2013 Share Posted September 17, 2013 (edited) Why are you replacing an ampersand with an ampersand here? a = ReplaceSubstring(a, "&" , "&"); You could do the replacement where you define 'a' like this: var a = Field("custom text")[color="Red"].replace("\\"," | ").replace("=","<br />");[/color] var b = "Custom Message Here"; if (Field("message type") == "custom") return a; else if (Field("message type") == "default") return b; I don't think you should have to replace anything for the 'b' variable. Since you're defining a static string, you'd just define it exactly as you'd like it to be returned. And more succinctly: return (Field("message type" == "default") ? "Custom Message Here" : Field("custom text")[color="Red"].replace("\\"," | ").replace("=","<br />")[/color]; Edited September 17, 2013 by step syntax Quote Link to comment Share on other sites More sharing options...
uph printshop Posted September 17, 2013 Author Share Posted September 17, 2013 I will try this. Web CRD doesnt interpret ampersands correctly I guess. I spoke with Web CRD's developer and he suggested I set the coding up like that. It worked okay. Thanks! Quote Link to comment Share on other sites More sharing options...
step Posted September 17, 2013 Share Posted September 17, 2013 Maybe try replacing the ampersand with the HTML entity character: return (Field("message type" == "default") ? "Custom Message Here" : Field("custom text").replace("\\"," | ").replace("=","<br />")[color="Red"].replace("&","&")[/color]; Quote Link to comment Share on other sites More sharing options...
uph printshop Posted September 17, 2013 Author Share Posted September 17, 2013 It is only replacing one equal sign(break). If the customer wants a double space, they would enter the equal sign twice. It is breaking the copy, but only once, not twice. It leaves the second equal sign as literal text. Am I missing something? Thanks! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 18, 2013 Share Posted September 18, 2013 It is only replacing one equal sign(break). If the customer wants a double space, they would enter the equal sign twice. It is breaking the copy, but only once, not twice. It leaves the second equal sign as literal text. Am I missing something? Thanks! The JavaScript String.replace function replaces only one instance of the matched substring, by default, unless the first parameter is a RegExp object with a "g" flag. So you could do this to fix it: if (Field("message type" == "default")) return "Custom Message Here"; //else return Field("custom text").replace(new RegExp("\\", "g"), " | ").replace(new RegExp("=", "g"), "<br />").replace(new RegExp("&", "g"), "&");Although in this case, I think using the FusionPro-specific ReplaceSubstring function is more clear, even if it's a bit less succinct: if (Field("message type" == "default")) return "Custom Message Here"; //else var a = Field("custom text"); a = ReplaceSubstring(a, "=" , "<br />"); a = ReplaceSubstring(a, "&" , "&"); a = ReplaceSubstring(a, "\\" , "|"); return a; Quote Link to comment Share on other sites More sharing options...
uph printshop Posted September 19, 2013 Author Share Posted September 19, 2013 This worked great with the addition of "ReplaceSubstring" in the second line. Thanks so much for your help!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.