473,473 Members | 4,297 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to change font size for web pages using Javascript & Coldfusion

Hello,

I have a website with various font options (small to large) buttons
that the user can click on the banner, which runs through the site.
Site contains both static and dynamic content. I have an onclick()
event on the buttons. But, I am not sure where to put the javascript
function that will change the stylesheet accordingly and how to write
this piece of code. Any help is appreciated.

Thanks,
jnag

May 24 '07 #1
3 21017
jnag wrote:
I have a website with various font options (small to
large) buttons that the user can click on the banner,
which runs through the site.
Site contains both static and dynamic content. I have
an onclick() event on the buttons. But, I am not sure
where to put the javascript function that will change
the stylesheet accordingly and how to write this piece
of code.
One way is to use a camelcase:

<script type="text/javascript">
function f(n) {
document.getElementById('C').style.fontSize = n
}
</script>
<div id="C">Text</div>
<input type="button" onClick="f('18px')" value="18px">
<input type="button" onClick="f('200%')" value="200%">
<input type="button" onClick="f('36pt')" value="36pt">
<input type="button" onClick="f('2cm')" value="2cm">
<input type="button" onClick="f('8em')" value="8em">
<input type="button" onClick="f('2.5in')" value="2.5in">
<input type="button" onClick="f('18pc')" value="18pc">

Variant, changing CSS-classes:

<head>
<title>My test page</title>
<style type="text/css">
.one { font-size: 22px }
.two { font-size: 6em }
</style>
</head>

<body>
<div id="C">Text</div>
<input type="button" value="22px"
onClick="document.getElementById('C').className='o ne'">
<input type="button" value="6em"
onClick="document.getElementById('C').className='t wo'">
</body>

Hope this helps,

--
Bart

May 25 '07 #2
On May 25, 5:29 am, Bart Van der Donck <b...@nijlen.comwrote:
jnag wrote:
I have a website with variousfontoptions(small to
large) buttons that the user can click on the banner,
which runs through the site.
Site contains both static and dynamic content. I have
an onclick() event on the buttons. But, I am not sure
where to put thejavascriptfunction that willchange
the stylesheet accordingly and how to write this piece
of code.

One way is to use a camelcase:

<script type="text/javascript">
function f(n) {
document.getElementById('C').style.fontSize = n
}
</script>
<div id="C">Text</div>
<input type="button" onClick="f('18px')" value="18px">
<input type="button" onClick="f('200%')" value="200%">
<input type="button" onClick="f('36pt')" value="36pt">
<input type="button" onClick="f('2cm')" value="2cm">
<input type="button" onClick="f('8em')" value="8em">
<input type="button" onClick="f('2.5in')" value="2.5in">
<input type="button" onClick="f('18pc')" value="18pc">

Variant, changing CSS-classes:

<head>
<title>My test page</title>
<style type="text/css">
.one { font-size: 22px }
.two { font-size: 6em }
</style>
</head>

<body>
<div id="C">Text</div>
<input type="button" value="22px"
onClick="document.getElementById('C').className='o ne'">
<input type="button" value="6em"
onClick="document.getElementById('C').className='t wo'">
</body>

Hope this helps,

--
Bart
Thanks. My problem is this. I have a index.cfm in which I have all the
<link rel="....") statements which define the various stylesheets.
Then, I have the <scripttag for the styleswitcher javascript
function. This index.cfm refers to modHeader.cfm in which I have the
call to the javascript function based on an onClick() event. I think
the javascript function is not being recognized, since the styles are
not changing though everything seems alright.

May 29 '07 #3
jnag wrote:
On May 25, 5:29 am, Bart Van der Donck wrote:
[ snip ]
> <head>
<title>My test page</title>
<style type="text/css">
.one { font-size: 22px }
.two { font-size: 6em }
</style>
</head>
> <body>
<div id="C">Text</div>
<input type="button" value="22px"
onClick="document.getElementById('C').className='o ne'">
<input type="button" value="6em"
onClick="document.getElementById('C').className='t wo'">
</body>
Thanks. My problem is this. I have a index.cfm in which
I have all the <link rel="....") statements which define
the various stylesheets.
No problem; you could use my second code example (with the CSS-
classes) and load the styles using

<link rel="stylesheet" href="profile.css" type="text/css">
Then, I have the <scripttag for the styleswitcher
javascript function. This index.cfm refers to modHeader.cfm
in which I have the call to the javascript function based on
an onClick() event. I think the javascript function is not
being recognized, since the styles are not changing though
everything seems alright.
It could be many things. I'm guessing at a typo, errorneous CSS/js
call, ...

Every page that uses the javascript and the CSS must load it
separately (so, both index.cfm and modHeader.cfm).

Could you post the (shortened) code that causes the problem ?

--
Bart

May 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Hill | last post by:
I have a perl script that i use to render a html page. In that page i call out a stylesheet. If the user has a 800x600 display the fonts are really too big. Since screen resolution is a function...
6
by: Liam Gibbs | last post by:
Does anyone know how to make input fields smaller, using a smaller font? I want to know how to make my textboxes and such like the ones at http://www.gracenote.com/music/ , but reading teh code...
15
by: lharby | last post by:
Basic question, is this possible? I have managed to crib a javascript function that allows the user to increase or decrease the font size of a page. (see...
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
0
by: csgraham74 | last post by:
Hi there, i have creted a datagrid control to display images using the following code. <asp:DataGrid id="dg_Properties" runat="server" HorizontalAlign="Center" Width="450px"...
4
by: hgraham | last post by:
I've recently noticed that there seems to be some font size differences (I'm guessing) in pages being viewed in FF 1.5 on my laptop which causes the whole layout to fall apart. You can see this...
1
by: roshina | last post by:
Hi Iam facing a problem in my project, developing a web site for online shopping in ASP on windows XP using IIS server. All the validations are ok but the new password is not upadated in the data...
3
by: coyttl | last post by:
Hey guys, I'm sure I'm doing something dumb but can't figure out exactly what it is... Here are details: XHTML Transitional pages with a linked CSS page. (See the CSS bits below) On Firefox...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.