Jump to content

Issues with Fractions


James

Recommended Posts

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

Screen-shot-2013-01-02-at-3_21.57-PM.jpg.a92dd4b49252dfa6280b5c6e29310274.jpg

Link to comment
Share on other sites

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>");

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! :)

Link to comment
Share on other sites

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

Screen-shot-2013-01-03-at-1_15.05-PM.jpg.3987a3457d89e908355517021d6a38aa.jpg

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...