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

  • Home
  • SEARCH
  • 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 8827231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:19:26+00:00 2026-06-14T07:19:26+00:00

To start off here’s how the application works: (note: there are multiple users on

  • 0

To start off here’s how the application works: (note: there are multiple users on the page like Patient M, Patient E, so on)

1) Next to Patient X’s name is a button labeled Check In. This is logged in the server side.

2) Upon clicking the Check In button , the user is then presented with a dropdown (replacing the initial button) with the multiple locations the user could choose. Upon selecting a location from the select, the server side is updated again.

3) The user then might decide to choose multiple locations, repeating step 2

4) At the end, when the user is done selecting locations, he clicks on the Check Out button in the same select where the user had clicked locations in steps 2 and 3, titled Check Out. Upon clicking this, it is sent to checkloc.php and logged.

5) Finally, the dropdown dissapears and the words Checked Out appear.

Unfortunately, the problem is that right now if I am Computer 1, and go through the process of clicking Check In, selecting a location, and checking out, this is completely apart from Computer 2 doing this.

Heres a diagram:

what I want to happen

So basically I need a way to grab the server code every few seconds and update the form elements with the current values. I’m a pretty new programmer, so code and tutorials would be extra helpful. Also, like I just mentioned, I am a new programmer, so if my code could be cleaned up in any ways that would be fantastic.

Thanks for any and all help! I’m glad to clarify any questions you have!

Heres the code:

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$('.locationSelect').hide();  // Hide all Selects on screen
$('.finished').hide();        // Hide all checked Out divs on screen
$('.checkOut').hide();

$('.checkIn').click(function() {
    var $e = $(this);
    var data = $e.data("param").split('_')[1] ;
    // gets the id  of button
    // You can map this to the corresponding button in database...
    $.ajax({
        type: "POST",
        url: "checkin.php",
        // Data used to set the values in Database
        data: { "checkIn" : $(this).val(), "buttonId" : data},
        success: function() {
            // Hide the current Button clicked
            $e.hide();
            // Get the immediate form for the button
            // find the select inside it and show...
            $('.locationSelect').show();
            $('.checkOut').show();
        }
    });
});

$('.locationSelect').change(function() {
    $e = $(this);
    var data = $e.data("param").split('_')[1] ;
    // gets the id  of select
    // You can map this to the corresponding select in database...
    $.ajax({
        type: "POST",
        url: "changeloc.php",
        data: { "locationSelect" : $(this).val(), "selectid" : data},
        success: function() {
            // Do something here
        }
    });
});

$('.checkOut').click(function() {
    var $e = $(this);
    var data = $e.data("param").split('_')[1] ;
    // gets the id  of button
    // You can map this to the corresponding button in database...
    $.ajax({
        type: "POST",
        url: "checkout.php",
        // Data used to set the values in Database
        data: { "checkOut" : $(this).val(), "buttonId" : data},
        success: function() {
            // Hide the current Button clicked
            $e.hide();
            $('.locationSelect').hide();
            // Get the immediate form for the button
            // find the select inside it and show...
            $('.finished').show();
        }
    });
});

});
</script>

and html:

<button class="checkIn" data-param="button_9A6D43BE-D976-11D3-B046-00C04F49F230">Check In</button>

<form method='post' class='myForm' action=''>
  <select name='locationSelect' class='locationSelect' data-param="location_9A6D43BE-D976-11D3-B046-00C04F49F230">
    <option value="0">Select a location</option>
    <option value='1'>Exam Room 1</option>
    <option value='2'>Exam Room 2</option>
    <option value='3'>Exam Room 3</option>
    <option value='4'>Exam Room 4</option>
  </select>
</form>
<button class="checkOut" data-param="cbutton_9A6D43BE-D976-11D3-B046-00C04F49F230">Check Out</button>

<div class='finished' style='color:#ff0000;'>Checked Out</div>

heres the server side code ( I split it into three pages just for testing)

checkin.php

<?php

date_default_timezone_set('America/Denver');

$apptid = $_REQUEST['buttonId'];
$currentlocationstart = date("Y-m-d H:i:s"); 

if(isset($_REQUEST['checkIn'])){
    $checkin = 0;
}


$hostname = 'localhost';

$username = '*******';

$password = '******';


$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);

$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($checkin,$currentlocationstart, $apptid));


?>

locationchange.php

<?php

date_default_timezone_set('America/Denver');

$apptid = $_REQUEST['selectId'];
$currentlocationstart = date("Y-m-d H:i:s"); 

if(isset($_REQUEST['locationSelect'])){
    $currentLocation = $_REQUEST['locationSelect'];
}


$hostname = 'localhost';
$username = '*****';
$password = '*******';


$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);

$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($currentlocation,$currentlocationstart, $apptid));

?>

and checkout.php

<?php

date_default_timezone_set('America/Denver');

$apptid = $_REQUEST['buttonId'];
$currentlocationstart = date("Y-m-d H:i:s"); 

if(isset($_REQUEST['checkOut'])){
    $checkin = 1000;
}


$hostname = 'localhost';

$username = '*********';

$password = '********';


$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);

$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($checkin,$currentlocationstart, $apptid));


?>
  • 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-06-14T07:19:27+00:00Added an answer on June 14, 2026 at 7:19 am

    You are referring to a methodology known as a “heartbeat”. I am going to post an example here, but first I’d like to give you a few pointers since, as you said, you are a new dev :).

    1) With JQuery, try to avoid using the class selector. It’s notoriously slow. Use the id selector wherever possible, or the nodename selector with a narrowed search scope if it isn’t possible. The browser uses the ID as a sort of “index” or “key” to the dom element, so it is the fastest search.

    2) PRELOAD! Even if you are going to use class selectors, don’t do

        $('.locationSelect')
    

    Over and over. If you are going to reference the same DOM element more than once, do this:

        var locationSelect = $('.locationSelect'); //this creates a reference
        $(locationSelect).whatever() //this uses the reference
    

    By doing this, you are only searching the DOM once. It won’t seem like a big deal with smaller apps, but as your app becomes more and more complicated, it takes more and more time to search to DOM for elements. By using a reference, you only search once.

    3) (Optional) I would RECOMMEND using an MVC platform like AngularJS (which is written by Google). MVC, or Model View Controller, allows you to update a “Model” (basically a JavaScript Object) and the “View” (the HTML) automatically adjusts its value using something called UI-Bindings. It’s a great way to go about developing an app from the get-go, but if you are already knee-deep in plain-jane code, it may not be practical for you. I’d still take a look at their tutorial to see what it could offer you: http://docs.angularjs.org/tutorial/

    Now on to your original question! Yes, this is completely possible with jQuery by using a methodology known as a heartbeat. A heartbeat allows you to emulate data persistence between the server and client. The more frequent the heartbeat, the more in-sync your clients will be, but the greater load on your webserver as well. It’s a balancing act.
    In a nutshell, it works something like this:

        setInterval(function(){
            $.ajax({
               url: 'heartbeatscript.php',
               method: 'post'
               //whatever data you want to send
            }).done(function(data){
               //do whatever with the returned result
            });
        },heartbeatInterval); //heartbeatInterval will be however many MS you want    
    

    I would also recommend using JSON to communicate between the client and server. JSON is easy to parse on both ends, and on the client end it is simply the fastest mechanism for parsing bulk data. JSON is parsed directly into a JavaScript object because the notation is literally what JS uses to store object Data within the browser anyway. XML is also a good choice. Both are very easy to get started with:

    Client Side:
    You can use jQuery to parse rudimentary XML:

        $('nodeName',xml);
    

    You can parse JSON into a JSO like this:

        var JSO = JSON.parse(JSONString);                           
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for reference here is a jsfiddle link: http://jsfiddle.net/STmwz/4/ To start off with, there is
To start off, here is the JSON response that I've been working on: {
I'm creating a simple questions DB, here are some details to start: 1st off,
This is more of a 2nd part of a question that start off here
if i start off on a Detail page: http:\\www.mysite.com\App\Detail i have a controller action
Basic problem here.. I will start off by asking that you please not respond
let's start off with the problem statement: My iOS application has a login form.
I'd like to start off by saying that I'm a complete beginner when it
I will start off by showing the JSON I would like to deserialize: {FleetsCollection:[{FleetId:2,Nickname:2007
I know there's already plenty of threads that start off this way. I'm reading

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.