Forum Moderators: coopster
the following is my code:
index.php
<?php
session_start();
$_SESSION['b1']=1;
$_SESSION['b2']=2;
$_SESSION['b3']=3;
?><a href="category.php"> click me </a>
Category.php
<?php
session_start();
?>
<html>
<body>
<input type="button" id="b<" name="b<" value="<" onClick="nextFunction('<')" />
<input type="button" id="b1" name="b1" value=<?php echo $_SESSION['b1'];?> onClick="nextFunction(<?php echo $_SESSION['b1'];?>)" />
<input type="button" id="b2" name="b2" value=<?php echo $_SESSION['b2'];?> onClick="nextFunction(<?php echo $_SESSION['b2'];?>)" />
<input type="button" id="b3" name="b3" value=<?php echo $_SESSION['b3'];?> onClick="nextFunction(<?php echo $_SESSION['b3'];?>)" />
<input type="button" id="b>" name="b>" value=">" onClick="nextFunction('>')" /><script type="text/javascript">
var myChar; // global variablefunction nextFunction(mystr) {
myChar=mystr;
window.setTimeout("delayit()", 1000);
}function delayit() {
var newV1=document.getElementById('b1');
newV1.value=parseInt(newV1.value);
var newV2=document.getElementById('b2');
var newV3=document.getElementById('b3');
if(myChar=='<'){
if(newV1.value==1)
return;
else{
newV1.value=parseInt(newV1.value)-1;
newV2.value=parseInt(newV2.value)-1;
newV3.value=parseInt(newV3.value)-1;
}
}
else if (myChar=='>'){
newV1.value=parseInt(newV1.value)+1;
<?php
$_SESSION['b1']=$_SESSION['b1']+1;
?>
newV2.value=parseInt(newV2.value)+1;
<?php
$_SESSION['b2']=$_SESSION['b2']+1;
?>
newV3.value=parseInt(newV3.value)+1;
<?php
$_SESSION['b3']=$_SESSION['b3']+1;
?>
}
else{
window.location.href = "/PM/" + myChar +"/";
}
}</script>
</body>
</html>
[edited by: eelixduppy at 11:59 am (utc) on Oct. 2, 2007]
[edit reason] disabled smileys [/edit]
You expected the PHP code inside your javascript function to run ONLY when the javascript function is called. But your PHP code is running whenever the page is loaded, no matter what you do. The reason is simiply your code doesn't know when to increment the value and there are no conditions to it, so it is just incrementing it all the time the page loads.
<?php
$_SESSION['b3']=$_SESSION['b3']+1;
?>
Habtom
but i still confuse what you said, because that the php does not have click button even,
just javascript has. For example,i can call a javascript function to do something for me
when i click a button, but i have not idea that call a php function to do something for
me when i click on button.
Could you tell me how to complete use php function?