...

View Full Version : functions and parameters



worldtraveller
12-06-2010, 04:58 AM
I need to create a function with named getFontSize()
needs one parameter named "id"
and id is value of object in document
then to create a variable named object to represent object
return font size of text in object
use style object to retrieve font size
and use parseInt() function to get value of font size

this is the code i came up with


function getFontSize(id) {
// Returns the font size of the object with the value id
var object=document.getElementById(id);
fontsize=parseInt(object.style.fontSize);
return(fontsize);
}

What should i change to make work/

Logic Ali
12-06-2010, 05:19 AM
For this to work, the element under test must have its font size styled inline, not via a class.
If that was done, how are you calling the function?

worldtraveller
12-06-2010, 12:03 PM
Well using everything from external files.


function placeIt(id, x, y) {
// Places the id object at the coordinates (x,y)
object=document.getElementById(id);
object.style.left=x+"px";
object.style.top=y+"px";
}


function getFontSize(id) {
// Returns the font size of the object with the value id
object=document.getElementById(id);
size=parseInt(object.style.fontSize);
return(size);
}

function setFontSize(id, ptsize) {
// Sets the font size of the object with the value id
object=document.getElementById(id);
object.style.fontSize = ptsize + "pt";
}

function changeFontSize(id, dfs) {
// Returns the font size of the object with the value id
fs = getFontSize(id);
setFontSize(id, fs+dfs);
}CSS

Old Pedant
12-06-2010, 08:02 PM
Now would you care to bother to answer LogicAli's question??

Did you read his post, at all?

You can throw all the code at this you want, but if you used a class to set the font size, then the font size you read from the object will be null.

worldtraveller
12-07-2010, 12:18 AM
understood now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum