I am incrementing a value of a hidden element using javascript ,
and posting it in the $_POST array.
But it increases only once , and then remains the same. Please help.
My file is incrementing.php with the below code:
<script language="Javascript">
function NextClicked()
{
document.getElementById("LabelClicked").value =
document.getElementById("LabelClicked").value + 1 ;
document.forms["incrementing"].submit();
}
</script>
<?php
if(isset($_POST['LabelClicked']) && $_POST['LabelClicked']>=1)
{
$_POST['LabelClicked'] = $_POST['LabelClicked'] +9;
}
?>
<?php
if(isset($_POST['clickednext']))
{
echo 'Value ='.$_POST['LabelClicked'];
}
else
{
echo "Not Clicked Yet";
}
?>
<form name = "incrementing" method="post" action="incrementing.php">
<div class=d2 align=left><a href="#" onclick=" NextClicked(); submit();">Next</a>
<input type = "hidden" id="LabelClicked" name="LabelClicked" />
</form>
Don’t you need to set the value of LabelClicked id to be what the new, incremented value is?
Otherwise it is incrementing from “” everytime. You should also make sure that you are treating
as an integer and not a string, or else you will get “111111”