0

Hi,
I would like to make two icons in my page so as to click on them and increase or decrease the font size of paragraph.
The problem I have is that I want to change the size only for a paragraph.

My paragraph's text is from a database.
So the id is different in each paragraph.

My code is :

<script type="text/javascript">
function resizeText(multiplier,p) {
   
  if (document.getElementById(p).style.fontSize == "") {
    document.getElementById(p).style.fontSize = "1.0em";
  }
  document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) + (multiplier * 0.2) + "em";
}
</script>


 $c=0; //counter for changing id name

//.... select from database 
//......

     while ($row = mysql_fetch_assoc($result))
     {
        $c = $c +1;
                  $text = ... // is from db
                  $p="par".$c;

echo "<p align='right'><img id='plustext' alt='Increase text size' src='images/ste.gif' width='19' height='29' onclick='resizeText(1,".$p.")'/></a>";
         
echo "<p align='justify' id='".$p."'>".$text."</p>";
          }

But it doesn't work.
Any help ?

Thanks a lot

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by nav33n
0

Not sure what exactly I changed, but this works.

<html>
<head>
<script type="text/javascript">
function resizeText(multiplier,p,what) {
	if (document.getElementById(p).style.fontSize == "") {
		document.getElementById(p).style.fontSize = "1.0em";
  	}
  	if(what == "increase") {
  		document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) + (multiplier * 0.2) + "em";
  	} else {
  		document.getElementById(p).style.fontSize = parseFloat(document.getElementById(p).style.fontSize) - (multiplier * 0.2) + "em";
  	}
}
</script>
</head>
<body>
<?php 
 $c=0;
 $c = $c +1;
 $text = "Click the button to increase the size of the font. Keep clicking it until you get tired.";
 $p="par".$c;

echo "<p align='right'><input type='button' name='button' value='Increase font' onclick='resizeText(1,\"$p\",\"increase\");' />";
echo "<p align='right'><input type='button' name='button' value='Decrease font' onclick='resizeText(1,\"$p\",\"decrease\");' />";         
echo "<p align='justify' id='".$p."'>".$text."</p>";
?>
</body>
</html>

Cheers!
Naveen

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.