Jump to content

Help with a new adventure.


Chocolate570

Recommended Posts

Well, i decided it was time i tried making something useful. To make a long story short, i failed completely. :)

<html><body id="bodyg"><script type="text/javascript">function changeSize(which){y = document.getElementById("bodyg").style.fontSizez=eval("y")if(which=='0'){  z++}else{  if(z!="1" && z!="0")  {    z=z+(-1*z)  }  else  {    return;  }}if(z!="0"){alert(z)y = document.getElementById("bodyg")y.style.fontSize=z}}</script><input type="button" value="Larger" onclick="changeSize('0')"><input type="button" value="Smaller" onclick="changeSize('1')">blahblahblah</body>

See, what that code does is gives you 2 buttons, one saying larger, one saying smaller. When you click the 'larger' button, it should make the text in the body bigger. It doesn't work, and i know very well why.But the problem is, when you click the smaller button, it can't make the text smaller because now the fontSize of the body is Zpx, where z= the number. I need to remove the px off that, so i decided to use replace(). One problem---i'm new with the pattern thing, forget new, i'm completely useless and have never tried it. So how would i remove the 'px' off the font size so i can reset it? :)Thanks in advance.~Chocolate570

Link to comment
Share on other sites

HiTry this code.

<html><body id="bodyg" style="FONT-SIZE: 20px">	<script type="text/javascript">	function changeSize(which)	{	var z;	var y;	y = document.getElementById("bodyg").style.fontSize	z = eval("y")	var ilen = z.length;	z = z.substring(0,ilen-2);	if(which=='0')  {  	z++  }	else  {  	z--  	//if(z!="1" && z!="0")  	//{  //  z=z+((-1)*z)  //	}  //	else  //	{  //  return;  	//}  }  if(z!="0")  {  	y = document.getElementById("bodyg")  	y.style.fontSize = z  }	}  </script>  <input onclick="changeSize('0')" type="button" value="Larger"> <input onclick="changeSize('1')" type="button" value="Smaller">blahblahblah	</body></HTML>

HTH

Link to comment
Share on other sites

Well, i decided it was time i tried making something useful. To make a long story short, i failed completely. :)~Chocolate570

lol - sorry I can;t help you with teh javascript right now, but I love the preface!!:)
Link to comment
Share on other sites

Lol, thanks Skemcin for the compliment. I think. :)Thanks so much, maelstorm. It worked beautifully. :) I'll give your name on it too if i submit it to any sites. Thanks again. :(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...