Click to See Complete Forum and Search --> : updating text


davey
11-27-2003, 09:33 PM
<html>
<head>
<title>Goku</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
<!--
var global=50;
function SetGlobal(param){
global+=param;
return global;
}

function Process(){
alert ("Original power = "+global+", new power = "+SetGlobal(50));
}
function Process2(){
alert ("Original power = "+global+", new power = "+SetGlobal(100));
}
function Process3(){
alert("Original power = "+global+", new power = "+SetGlobal(150));
}

var money=10000;
function Setmoney(param){
money+=param;
return money;
}
function Process5(){
alert("Original money = "+money+", current balance = "+Setmoney(500));
}
function Process6(){
alert("Original money = "+money+", current balance = "+Setmoney(200));
}
function Process7(){
alert("Original money = "+money+", current balance = "+Setmoney(50));
}



//-->
</script>
</head>

<body bgcolor="#6DBE25">
<p align="center"><font color="#FFFF00">Goku's Profile</font></p>
<p align="center"><font color="#ffff00"><a href="login.html">Back To Player List</a></font></p>
<p align="center"><img src="goku.jpeg" width="227" height="305"></p> <p></p>
<center><table width="75%" border="4" cellspacing="2" cellpadding="2">
<tr>
<td><font color="#FFFF00"><strong>Power:</strong></font></td>
<td><font color="#FFFF00"><strong>Money:</strong></font></td>

</tr>
<tr>
<td><font color="#FFFF00"><SCRIPT LANGUAGE="JavaScript">
<!--
document.write("<FONT COLOR='#ffff00'>Your power is " + global + ".</FONT>");
// -->
</SCRIPT>
</font></td>


<td><font color="#FFFF00"><SCRIPT LANGUAGE="JavaScript">
<!--
document.write("<FONT COLOR='#ffff00'>You have " + money + " dollars.</FONT>");
// -->
</SCRIPT></font></td>
</tr>
</table></center>
<br>
<p><center>
<table width="75%" border="4" cellspacing="2" cellpadding="2">
<!--DWLayoutTable-->
<tr>
<td height="28" colspan="2" valign="top"><center>
<font color="#FFFF00"><strong>Fight Log: </strong></font>
</center></td>
</tr>
<tr>
<td width="303"><font color="#FFFF00">wins:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</font></td>
<td width="303"><font color="#FFFF00">loses:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</font></td>
</tr>
</table>
</center><p></p>
<p><center>

<table width="75%" border="4" cellspacing="2" cellpadding="2">
<tr>
<td><center><font color="#FFFF00">Training</font> </td>
<td><center><font color="#FFFF00">Earn Money</font> </td>
</tr>
<tr>
<td><center><input type="button" value="Punch" onclick="Process()"/></td>
<td><center><input type="button" value="Work" onclick="Process5()"/></td>
</tr>
<tr>
<td><center><input type="button" value="Kick" onclick="Process2()"/></td>
<td><center><input type="button" value="Steal" onclick="Process6()"/></td>
</tr>
<tr>
<td><center><input type="button" value="Energy" onclick="Process3()"/></td>
<td><center><input type="button" value="Beg" onclick="Process7()"/></td>
</tr>
</table>
</center>

</body>
</html>



after the processes run they change the variable but

<SCRIPT LANGUAGE="JavaScript">
<!--
document.write("<FONT COLOR='#ffff00'>You have " + money + " dollars.</FONT>");
// -->
</SCRIPT> doesnt update how can i get these two to update with the variable?

ray326
11-27-2003, 11:36 PM
Here are a couple of hints.

function Process(){
alert ("Original power = "+global+", new power = "+SetGlobal(50));
document.getElementById("power").innerHTML="<FONT COLOR='#ffff00'>Your power is " + global + ".</FONT>";
}

And in the body

<td>
<div id="power">
<font color="#FFFF00"><SCRIPT LANGUAGE="JavaScript">
<!--
document.write("<FONT COLOR='#ffff00'>Your power is " + global + ".</FONT>");
// -->
</SCRIPT>
</font>
</div>
</td>

And the whole mess would be a lot easier if you were using CSS instead of deprecated font tags and such.

ray326
11-27-2003, 11:42 PM
What the heck. Here's a cleaned up version.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">
<html xmlns="http://www.w3.org/TR/xhtml1">
<head>
<title>
Goku
</title>
<style type="text/css">
body { background-color: #6DBE25; color: yellow; text-align: center; }
</style>
<script type="text/javascript">
<!--
var global=50;
function SetGlobal(param){
global+=param;
return global;
}

function Process(){
alert ("Original power = "+global+", new power = "+SetGlobal(50));
updatePower();
}
function Process2(){
alert ("Original power = "+global+", new power = "+SetGlobal(100));
updatePower();
}
function Process3(){
alert("Original power = "+global+", new power = "+SetGlobal(150));
updatePower();
}
function updatePower()
{
document.getElementById("power").innerHTML="Your power is " + global + ".";
}

var money=10000;
function Setmoney(param){
money+=param;
return money;
}
function Process5(){
alert("Original money = "+money+", current balance = "+Setmoney(500));
updateMoney();
}
function Process6(){
alert("Original money = "+money+", current balance = "+Setmoney(200));
updateMoney();
}
function Process7(){
alert("Original money = "+money+", current balance = "+Setmoney(50));
updateMoney();
}
function updateMoney()
{
document.getElementById("money").innerHTML="You have " + money + " dollars.";
}



//-->
</script>
</head>
<body>
<p>Goku's Profile</p>
<p><a href="login.html">Back To Player List</a></p>
<p><img src="goku.jpeg" width="227" height="305" /></p>
<table width="75%" border="4" cellspacing="2" cellpadding="2">
<tr>
<td>
<strong>Power:</strong>
</td>
<td>
<strong>Money:</strong>
</td>
</tr>
<tr>
<td>
<div id="power">
<script language="JavaScript" type="text/javascript">
document.write("Your power is " + global + ".");
</script>
</div>
</td>
<td>
<div id="money">
<script language="JavaScript" type="text/javascript">
document.write("You have " + money + " dollars.");
</script>
</div>
</td>
</tr>
</table>



<table width="75%" border="4" cellspacing="2" cellpadding="2">
<!--DWLayoutTable-->
<tr>
<td height="28" colspan="2" valign="top">
<strong>Fight Log:</strong>
</td>
</tr>
<tr>
<td width="303">
wins: 0
</td>
<td width="303">
loses: 0
</td>
</tr>
</table>

<table width="75%" border="4" cellspacing="2" cellpadding="2">
<tr>
<td>
Training
</td>
<td>
Earn Money
</td>
</tr>
<tr>
<td>
<input type="button" value="Punch" onclick="Process()" />
</td>
<td>
<input type="button" value="Work" onclick="Process5()" />
</td>
</tr>
<tr>
<td>
<input type="button" value="Kick" onclick="Process2()" />
</td>
<td>
<input type="button" value="Steal" onclick="Process6()" />
</td>
</tr>
<tr>
<td>
<input type="button" value="Energy" onclick="Process3()" />
</td>
<td>
<input type="button" value="Beg" onclick="Process7()" />
</td>
</tr>
</table>

</body>
</html>