Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:41:45+00:00 2026-05-17T19:41:45+00:00

I hava set up AJAX script that when you click the button it calls

  • 0

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&rsquo;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&rsquo;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!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:41:46+00:00Added an answer on May 17, 2026 at 7:41 pm

    in your javascript, you can do something like this

    var isChecked = document.myform.checkbox.checked ? 1 : 0;
    xmlhttp.open("GET","roulette.php?boxchecked=" + isChecked,true);
    

    Then, in your php, you can read $_GET['boxchecked'], which will be 1 if the box was checked, 0 if it wasn’t.

    EDIT: Extending the idea to more than one field.
    To do this, you’d add as many checkboxes as you want, say they’re names are value1, value2, value3, .... Then you can do something like this:

    var value1 = document.myform.value1.checked ? 1 : 0;
    var value2 = document.myform.value2.checked ? 1 : 0;
    var value3 = document.myform.value3.checked ? 1 : 0;
    ...
    

    and

    xmlhttp.open("GET","roulette.php?value1=" + value1 + "&value2=" + value2 + "&value3=" + value3 ...,true);
    

    In php, read $_GET['value1'], $_GET['value2'], $_GET['value3']...

    Once you get the concepts, you can write some functions to reduce the duplication, if you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hava a problem with this mssql_query in PHP : $query = 'SELECT Ville
I hava a Java program that needs to monitor a directory tree for changes.
I hava a CSV file that I want to treat as source code. Essentially
Is it possible to debug a shell script in IntelliJ IDEA 9.0.3. I hava
I hava a application that works with pictures(just a full screen app with 3
I hava a servleta that serves files? I'm building a page with a Download
Here's the thing. I hava a simple snippet in PHP like this regarding a
I hava java swing project which is developed in JBuilder IDE. Now I need
I hava a url such as search.do?offset=20 offset sometimes is in the url sometimes
I hava a table in a scrollPane . There are 6 columns in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.