Jump to content

Correction for my "if ... else if ... else" statement !?


Yammaski

Recommended Posts

I need a correction in my script/syntax, so that I can make calculations depending on the fontFamily (css : @fontface) that's selected. In the code of my testpage, it's the : function getH() that start at 134.The purpose of this is to get the px-width & -height of the text input. The height is for every font different and has to be adjust by a ...factor.

Link to comment
Share on other sites

if (changeFont==('Arial'))changeFont is a function, not a string. If you're trying to get the currently selected font, you'll either need to get the select element and figure out which option is selected, or have the changeFont function set a global variable that tracks the font.

Link to comment
Share on other sites

changeFont is a function. You must call it like a function, with parentheses. You define the function with a parameter also, so you probably need to pass it one. I think you are trying to pass changeFont values like "Arial" and "Balloon." You don't do that with the == operator. It would have to look like this:changeFont("Balloon");But notice that changeFont has no return value. The result of an if-test will always be FALSE.I really don't know that you are trying to accomplish with those if-blocks. Maybe you can explain your purpose and someone will suggest a better structure.EDIT. I see the paranoid pirate ninja has paid us a social call.

Link to comment
Share on other sites

i think the font attributes of an input will be dictated by the font of your page. If your font is like, say 22px, I think the inputs will adjust accordingly, to allow that size font to fit in it. Are you thinking people would be able to insert huge block of code?Or are you trying to give people the option to set the size and font-family, and then have the page change accordingly?

Link to comment
Share on other sites

If you're trying to get the currently selected font, you'll either need to get the select element and figure out which option is selected, or have the changeFont function set a global variable that tracks the font.
That's what I'am trying. But how do I do this ... set a global var that tracks the font ... ?
I really don't know that you are trying to accomplish with those if-blocks.
I want the font that's selected. If the font is 'Arial' then I have to multiply the height with 1.57 ... if the font ... .I need another calculation for every font, because their standard height is different.
Link to comment
Share on other sites

A global variable in Javascript is one that you don't redefine with var inside of a function.

var selectedFont = '';function changeFont(str){  selectedFont = str;}function test1(){  alert(selectedFont); // global}function test2(){  var selectedFont;  alert(selectedFont);  // not global}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...