I want that when a user checks my checkbox it will not appear again. But my script is running, so when the script is run a second time it is not displayed even though the user did not check my checkbox. All my pages are coming through ajax.
if (!in_array('checked', $_SESSION["questy"]))
{
?>
<div id="fifty" style="width:150px; height:25px; float:right" >
<input class="bigcheck" type="checkbox" id="cb" onclick="hiding()"/>
<span style="color:#FFF;font-size:20px;font-family:Arial, Helvetica, sans-serif;font-weight:lighter;">50/50</span>
</div>
<?php }?>
function hiding(){
document.getElementById('<?php echo $ran1;?>').setStyle({"display":"none"});
document.getElementById('<?php echo $ran2;?>').setStyle({"display":"none"});
document.getElementById('fifty').setStyle({"display":"none"});
var c=document.getElementById('cb').getChecked();
alert(c);
if(document.getElementById('cb').getChecked()== true)
{
<?php
$_SESSION["questy"][] = 'checked';
?>
}
}
You're mixing up server side PHP and client side Javascript. That can never work. All PHP is executed before the page is sent to the browser.
What you should be doing is either use Ajax to submit the changed situation to the server so it can process it server side in a new page; or process it (server side) after submit of the form.