Changing Fon't face & Size.

She has: 2 posts

Joined: Nov 2005

This may not be the best way to pull this off.. but it's been the only way I found to make it work.. But the way I'm doing it leads to some issues..

I got a PHP page that is using an include to add in the contents. And using an IF to change the font type used. But the issue is, if I want to change the text content via a link, I have to use the code on each and every page rather then just having the file in the include change..

Heres what I've been using..

<?php
extract
($HTTP_GET_VARS);
$ftype = \"Font: <a href=\\"?font=Verdana\\"><font face=\\"Verdana\\">Verdana</font></a> | <a href=\\"?font=Serif\\"><font face=\\"Serif\\">Serif</font></a> | <a href=\\"?font=Arial\\"><font face=\\"Arial\\">Arial</font></a></font>\";
if (
$font == \"\"){
echo \"<div align='right'><font size=2>\" .
$ftype . \"</div></font>\";
print (' <font face=\"Verdana\" size=\"2\"> ');
}
if (
$font == \"Verdana\"){
echo \"<div align='right'><font size=2>\" .
$ftype . \"</div></font>\";
print (' <font face=\"Verdana\" size=\"2\"> ');
}
if (
$font == \"Serif\"){
echo \"<div align='right'><font size=2>\" .
$ftype . \"</div></font>\";
print (' <font face=\"Serif\" size=\"2\"> ');
}
if (
$font == \"Arial\"){
echo \"<div align='right'><font size=2>\" .
$ftype . \"</div></font>\";
print (' <font face=\"Arial\" size=\"2\"> ');
}
print (' <hr> ');
include('content1.txt');
?>

Now that works as is.. but still.. I'd like to keep the ability to change the font size, but change what the include shows so I'm running it off one PHP file, rather then having that same code on -every- page just to change the font..

If I end up stuck using this code, that I don't mind really.. I would like to know how I could change the file listed in the include via a link click, so all the other remains the same.

I also wanted to be able to change the font face, and size separately, but I couldn't find any way to do it..

So.. anyone got a better way to do this? Or to allow me to in the least change what the include displays via a link click? (like with the font size)

"Naku ga yousuru ichidanto tsuyosa kyaku ga icchuu wo yusuru."

chrishirst's picture

He has: 379 posts

Joined: Apr 2005

the easiest way is with DHTML (CSS & javascript)

&lt;script type="text\javascript"&gt;
function setFont(FontName,FontSize) {
var FontDim = "em" // can be "px", "pt" etc
if (FontName != "") {
document.getElementById("changeable").style.fontFamily = FontName;
}
if (FontSize != "") {
document.getElementById("changeable").style.fontSize = FontSize+FontDim;
}
}
&lt;/script&gt;
'

Page Code

<body>
Change Font To;
<br>
<a href="#" onClick="setFont('Verdana','1.2')">Verdana 1.2em</a>
<br>
<a href="#" onClick="setFont('Arial','1.2')">Arial 1.2em</a>
<br>
<a href="#" onClick="setFont('Verdana','1.8')">Verdana 1.8em</a>
<br>
<a href="#" onClick="setFont('Serif','1.0')">Serif 1.0em</a>

<div id="changeable">
Just some text for font demonstration
</div>

</body>
'
If you just want to change the size or just the font send the other parameter as an empty string ('') in the onClick event call.

Chris

Indifference will be the downfall of mankind, but who cares?
Venue Capacity Monitoring
Code Samples

She has: 2 posts

Joined: Nov 2005

Ahh.. alright thank you! This does look to work a lot better.

Though I was still wondering if there was away to change the font face and size separately. Rather then one link changing both. But rather one does the font face, and another link makes the text bigger or smaller.

"Naku ga yousuru ichidanto tsuyosa kyaku ga icchuu wo yusuru."

chrishirst's picture

He has: 379 posts

Joined: Apr 2005

Ermm Yes.

Quote: If you just want to change the size or just the font send the other parameter as an empty string ('') in the onClick event call.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.