why is it that when i click button2 to echo $_SESSION['sum'] on next page, the result show as 8 as if the function addtext(num) has been called, even though button1 has not been clicked ?
thank you
button5.php
<?php
session_start();
if (!isset($SESSION['sum'])) {$SESSION['sum']=10;}
$sum = $_SESSION['sum'];
$nu =2;
?>
//FILLS TEXT BOX AND TAKE $nu OFF SESSION VAR
<script language="javascript" type="text/javascript">
function addtext(num) {document.form2.textarea1.value= <?php
$SESSION['sum']=$sum - $nu ;
echo $SESSION['sum'];?>;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
//BUTTON1
<input type="submit" name="Submit" value="Submit" onclick="addtext(<?php echo $nu; ?>)"/>
</label>
</form>
<form id="form3" name="form3" method="post" action="button6.php">
<label>
//BUTTON2
<input type="submit" name="Submit2" value="Submit" />
</label>
</form>
<p> </p>
<form name="form2" method="post" action="">
<label>
<textarea name="textarea1" id="textarea1"></textarea>
</label>
</form>
<p> </p>
</body>
</html>
button6.php
<?php
session_start();
$suma = $_SESSION['sum'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body><?php echo $suma ;?>
</body>
</html>