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 6075377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:29:16+00:00 2026-05-23T10:29:16+00:00

I am pretty much new to coding but i am learning along the way.

  • 0

I am pretty much new to coding but i am learning along the way. i managed to make my buttons in php etcetera but ofcource this refreshes the page which made it very annoying.

I looked around and came to know Ajax. i managed to get certain page parts to auto refresh it’s data and i also managed to make a button that changes it’s test from Ready / Not Ready and sending data to a php file that processes it and updates the database.

However i am facing with one problem. for example, if a user uses the button sometimes and the database value is set to Ready. if they refresh the page. or close and come back the button would say it’s default value Ready while the database already has it set Ready.

The eventual goal is that a user can set his status to ready or not ready for a game match. where the database gets updated so that info can be shown to other users.

I will post my code below, sorry if the code is a mess i can understand it very well might be since i took the pieces from examples on the internet.

var xmlHttp_five = AJAX();
function ajaxFunction(pid) {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlHttp_five) { 
    var txtname = document.getElementById("txtname");
    xmlHttp_five.open("POST","includes/gather_buttons.php",true); //calling testing.php using POST method
    xmlHttp_five.onreadystatechange  = handleServerResponse;
    xmlHttp_five.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp_five.send("txtname=" + txtname.value + "&pid=" + pid); //Posting txtname to PHP File
  }
}

function handleServerResponse() {
   if (xmlHttp_five.readyState == 4) {
     if(xmlHttp_five.status == 200) {

        if (document.myForm.button1.value == "Ready") {
            document.myForm.button1.value = "Not Ready";
            document.myForm.txtname.value = "Waiting";
        } else {
            document.myForm.button1.value = "Ready";
            document.myForm.txtname.value = "Ready";
        }
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}

and the form below

<form name='myForm'>
    <input type='hidden' name='txtname' id='txtname' value='Ready'/>
    <input type='button' class='button2' id='button1' value='Ready' onclick='ajaxFunction($pid);' />
</form>

If i need to give more info please say so, sorry if i am not supposed to post this here.

Thank you in advance.

Best regards,

Johan

  • 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-23T10:29:17+00:00Added an answer on May 23, 2026 at 10:29 am

    Your form should be generated by server-side script. So when user refreshes page, he gets actual data from the database.

    Otherwise if you can’t generate form by server-side script, you should use preloader: button’s value initially should be “loading…” and script should request the value by Ajax.

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

Sidebar

Related Questions

I am pretty much new in this. I know Remoting, HTTPService and WebService. I
Please allow me to preface this by saying I'm pretty much brand new to
I've been coding in c++ for 3-4 years now, but I'm pretty new to
I'm pretty new to cocoa and Xcode, I've done some basic C coding, but
I am pretty much new to using SQL Server 2000. I have been using
I am completely new to android, and pretty much a Java newb. I have
I'm new to the .NET compact framework (and pretty much new to C# as
I'm pretty much completely new to the world of computer programming, so it's been
Im pretty much new to data mining and recommendation systems, now trying to build
I`m pretty much new in as3 and I came with a doublet, the statements

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.