Hi,
I hava set up AJAX script that when you click the button it calls a PHP document.
The problem I have is now some of the variables of the PHP file are set to constant, and now I want them to be conditional to what gets sent when the button is clicked.
I want there to be a check box, that if clicked, will set a PHP variable to be TRUE, while if not click, is set to be FALSE.
I hope the problem is clear enough.
I will now paste the code below because it may help to clarify the problem.
Sorry I have to paste this "huge" chunk of code but I´m not sure which may be useful and which not.
Here is index.html
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","roulette.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Welcome to Trufa’s Roulette</h2></div>
<button type="button" onclick="loadXMLDoc()">Spin the Wheel!</button>
</body>
</html>
And here is part of roulette.php
### Comprare pick to result
//The squares
$sqr_00 = -1;
$sqr_0 = 0;
$sqr_1 = 1;
//Placed bets, if true he placed bet
$bet_straight_placed = array(
$sqr_00 => false,
$sqr_0 => true,
$sqr_1 => true
);
What I would need as I told before, is to replace the FALSE in $sqr_00 => false
, for a variable that is true when the checkbox is checked!
I hope the question is clear enough to be understood but PLEASE ask for any clarifications needed!
Thanks in advance!
Trufa
EDIT:
Addressing @grossvogel reply I am posting what I understood of his answer becuse it is not working. Sorry and thank you very much!
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","roulette.php",true);
xmlhttp.send();
}
var isChecked = document.myform.checkbox.checked ? 1 : 0;
xmlhttp.open("GET","roulette.php?boxchecked=" + isChecked,true);
</script>
</head>
<body>
<div id="myDiv"><h2>Welcome to Trufa’s Roulette</h2></div>
<form name="myform">
<input type="checkbox" name="checkbox" value="checkbox" />00<br />
<button type="button" onclick="loadXMLDoc()">Spin the Wheel!</button>
</form>
</body>
</html>
and the php
//The squares
$sqr_00 = -1;
$sqr_0 = 0;
$sqr_1 = 1;
//Placed bets, if true he placed bet
$chb_00 = $_GET['boxchecked'];
$bet_straight_placed = array(
$sqr_00 => (bool) $chb_00,
$sqr_0 => true,
$sqr_1 => true
);
//tell the user what number he piecked
echo "You chose this numbers: " . join(", ", array_keys(array_filter($bet_straight_placed))) . '<br />' . '<br />';
I´m sorry I know this must be totally basic but I cant get my head around this AJAX "thing" yet.
Thank you!!!