Hi all
I am fairly new to javascript, and can't seem to get my head wrapped around working with arrays.
Here is the code that I have developed so far, however you will see the same code repeated twice. I know that an Array will solve this, but???
Code:
<script language="JavaScript" type="text/javascript">
/*********** Add onload="pointconversion()" to the Body Tag ***********/
function pointconversion() {
var y = document.getElementsByTagName('font');
for (var i=0;i<y.length;i++) {
var strlength =document.getElementsByTagName('font')[i].style.fontSize.length;
var pointsorpixels =document.getElementsByTagName('font')[i].style.fontSize.substr(strlength-2,2);
if (pointsorpixels=="pt")
{
var newsize=Math.ceil(parseFloat(document.getElementsByTagName('font')[i].style.fontSize)*1.3);
document.getElementsByTagName('font')[i].style.fontSize = newsize;
}
}
var y = document.getElementsByTagName('div');
for (var i=0;i<y.length;i++) {
var strlength =document.getElementsByTagName('div')[i].style.fontSize.length;
var pointsorpixels =document.getElementsByTagName('div')[i].style.fontSize.substr(strlength-2,2);
if (pointsorpixels=="pt")
{
var newsize=Math.ceil(parseFloat(document.getElementsByTagName('div')[i].style.fontSize)*1.3);
document.getElementsByTagName('div')[i].style.fontSize = newsize;
}
}
}
</script>
I know that it all starts with something like this, but from there I am lost.
Code:
tagtype = new Array('div','font')
The code works well the way it is, but in my opinion it looks sloppy.
What this code does is simply change all of the Font-Size's from points to pixels to handle the 120 dpi setting on some monitors.
I also call this code from the Body Tag, but perhaps there is some other way that it can be done.
If there are any other suggestions as to how I can shorten the code or improve on it, that would be appreciated as well.
Thanks, Loren