Hi All.
I want to allow users to select a font using a dropdown box. As every body has different fonts installed, how do I read the available fonts. I know this will be a very long list, but will not be used very often. I will store the selected font and size on a database for later use.
Thanks

I think that you need to stick to common fonts because you can't find out what fonts they may have installed, and if you could then you might have a list of too many fonts, some of which may not display on a web page. For example, on my computer I have hundreds of fonts installed, so you can imagine the trouble that you can get into.

As for loading a font to be used in a web page, that's no problem, but initially you don't need to use a database at all if you can write the font name to a cookie, which may be better because the user gets the same font loaded when they return.

So all you need to do is create a dropdown in a form with some font names listed. Use a submit button or an onchange statement to submit the new info to the same page for the page to load the font.

<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
<%
strFont = request("Font")
if strFont <> "" then
    response.cookies (Font)("Style") = strFont
end if

if Request.Cookies(Font) <> "" then
   strFontSet = Request.Cookies(Font)("Style")
else
   strFontSet = "Tahoma"    'set a default font
end if

%>
<form action="">
<select name="Font" size="1" onchange="MM_jumpMenu('parent',this,0)">
<option value="Arial">Arial</option>
<option value="Verdana">Verdana</option>
</select>
</form>
<br>
<font face="<%= strFontSet %>">This is my text</font>

I didn't test this code, but it should give the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.