Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pixels and points

Status
Not open for further replies.

imadmarie

Programmer
Nov 14, 2001
14
JO
hi guys, what im trying to do is to find a function in javascript that converts from points to pixels, or vice versa, no luck so far !! any help ?
 
Your in luck!!! Im currently working on this function for myself. At the momment it just converts from points to pixels..not the other way round as yet. I have also created it so that you can view your text in diffent hex colours and also changes the font and sizes accodingly along with the colour backgruond you use. If you advance this function..let me know so i can use it as well. here is the code:
...........................................................
file: p2p_frame.htm
...........................................................

<frameset rows=&quot;52%,*&quot;>
<frame name=&quot;topScript&quot; src=&quot;p2p_input.htm&quot; marginwidth=&quot;10&quot; marginheight=&quot;10&quot; scrolling=&quot;auto&quot; frameborder=&quot;0&quot;>
<frame name=&quot;bottomAnswer&quot; src=&quot;p2p_displayText.htm&quot; marginwidth=&quot;10&quot; marginheight=&quot;10&quot; scrolling=&quot;auto&quot; frameborder=&quot;0&quot;>
</frameset>

...........................................................
file: p2p_input.htm
...........................................................

<script language=&quot;javascript&quot;>


function convert() {

var i = 0

i = parseInt(document.myForm.myPoint.value)
if (i>=7 && i<=7){
answer = i+2
document.myForm.myAnswer.value = answer
} else if (i>=8 && i<=10){
answer = i+3
document.myForm.myAnswer.value = answer
} else if (i>=11 && i<=13){
answer = i+4
document.myForm.myAnswer.value = answer
} else if (i>=14 && i<=16){
answer = i+5
document.myForm.myAnswer.value = answer
} else if (i>=17 && i<=19){
answer = i+6
document.myForm.myAnswer.value = answer
} else if (i>=20 && i<=22){
answer = i+7
document.myForm.myAnswer.value = answer
} else if (i>=23 && i<=25){
answer = i+8
document.myForm.myAnswer.value = answer
} else if (i>=26 && i<=28){
answer = i+9
document.myForm.myAnswer.value = answer
} else if (i>=29 && i<=31){
answer = i+10
document.myForm.myAnswer.value = answer
} else if (i<=7){
document.myForm.myAnswer.value = &quot;Font Size too small!!&quot;
}

//var answerFont
//var answerFontColor
//var answerBgColor


answerFont = document.myForm.myFont.value
answerFontColor = document.myForm.myFontColor.value
answerBgColor = document.myForm.myBgColor.value
answerTextarea = document.myForm.myTextarea.value

parent.bottomAnswer.location.href = &quot;p2p_displayText.htm&quot;




}
</script>

...........................................................
file: p2p_displayText.htm
...........................................................

<script language=&quot;javascript&quot;>

var writeline = &quot;<body bgcolor=&quot;+parent.topScript.answerBgColor+&quot;>&quot;
writeline += &quot;<div id=\&quot;myLayer\&quot; style=\&quot;position:absolute; top:10; left:10; font-size:&quot;+parent.topScript.answer+&quot;px; font-family:&quot;+parent.topScript.answerFont+&quot;; color:#&quot;+parent.topScript.answerFontColor+&quot;; visibility:visible;\&quot;>&quot;
writeline +=&quot;<b>&quot;+parent.topScript.answerTextarea+&quot;</b>&quot;
writeline +=&quot;</div>&quot;
document.write(writeline);
</script>

...........................................................

Hope this was of some help. Let me know how you get on.
 
nope, i tried this function, it gives me incorrect results, ive been reading ur code too, having been able to understand what its supposed to do !!! what if i give the function (convert) a parameter of 500 , what happens ?
 
Where i have written &quot;file: p2p_displayText.htm, p2p_frame.htm, and p2p_input.htm&quot; etc. the parts under it are related to that page. You need to create the three pages that I have given you, open the p2p_frame.htm file. The code will only work if its in the frameset that i have given you.

I think what you might have done is just tried to run the script for the p2p_input.htm page and its giving you errors...which it would. The script does work as I have literally just cut and pasted the parts from each of the three pages.

I will try and put it online for you if i can find some time and some space.

Hope this has helped,

ps you dont need add anything to the convert function for now....once you have it working as i have coded it...try and modify it a bit. I am still working out bits a peices.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top