James Posted January 2, 2013 Posted January 2, 2013 I am working on a birth announcement that needs to have fractions available for the height. My original idea was to offer the fractions in a form note so that customers could simply copy and paste into the height field. I uploaded the template and previewed it, but it didn't work, the result gave me other special characters instead of the fractions. I figured it was an issue with the font, which didn't hurt my feelings because the fractions for that font aren't ideal anyway. My second idea was to create the fractions in Adobe Illustrator, save them as eps files and make them available as a "drop down menu, variable inline graphic" (if that is such a thing). I need the fractions to be available in the menu, but if no value is chosen, I need it to suppress the space and close the gap where the fraction would be. Am I anywhere near the right track? I've attached a visual. Thanks! James Quote
step Posted January 2, 2013 Posted January 2, 2013 As opposed to making a graphic for all types of fractions, would this solution help you? Where the template is passed a fraction (ex: 1/2) and the number before the slash is superscripted and the number following the slash is subscripted? var fraction = "40 1/4"; return fraction.replace(/(\d*)\/(\d*)/g,"<superscript>$1</superscript>/<subscript>$2</subscript>"); Quote
James Posted January 3, 2013 Author Posted January 3, 2013 Now there's an idea, I didn't even think about that. I'll give it a shot and see if that's what I need. On a side note, I only planned on making 1/4, 1/2 & 3/4 available on the dropdown menu. After a quick poll around the office, no one's child had any other fraction in their height measurement. Thanks step, I appreciate the help! Quote
James Posted January 3, 2013 Author Posted January 3, 2013 Just when I thought I had a bit of a handle on this JavaScript stuff, reality slaps me in the face with the word NOVICE!!! I'm doing something wrong. I keep getting a syntax error "missing ) after condition" if (Field("Inches") .indexof var fraction = "40 1/4"; return fraction.replace(/(\d*)\/(\d*)/g,"<superscript>$1</superscript>/<subscript>$2</subscript>"); What am I doing wrong? James Quote
step Posted January 3, 2013 Posted January 3, 2013 The syntax error is because of the if statement. Proper syntax for an if statement is: if (condition) { return do this; } else { return do that; } Secondly, the indexOf is a function that finds the first occurrence of a passed character in a specified string. For example: var fraction = "40 1/4"; return fraction.indexOf("4"); would return 0 meaning there is a 4 in the first position on the fraction string ("40 1/4"). return fraction.indexOf("6"); would return -1 meaning there is no "6" in that string. That being said, I'm not sure either of those are necessary for what you're trying to do. The var that I gave you ("var fraction") was simply a placeholder string for your field. So that just needs to be assigned to your Field ("Inches") or simply erase that part and replace the "fraction" variable with your field like so: return Field("Inches").replace(/(\d*)\/(\d*)/g,"<superscript>$1</superscript>/<subscript>$2</subscript>"); Hopefully that helps explain the error as well as gets you back on track with what you're trying to accomplish! Quote
James Posted January 3, 2013 Author Posted January 3, 2013 Makes sense. I really appreciate your explanation. My problem is I do a couple of JavaScript rules without help and my ego gets big This script worked for me. I had to tinker with the settings, the subscript was going too low, but it looks good. Here's a screenshot. Thanks for your help! James Quote
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.