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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:34:23+00:00 2026-06-13T09:34:23+00:00

I have a couple form elements that when clicked update the database and disappear.

  • 0

I have a couple form elements that when clicked update the database and disappear.

At first, I have a button that reads Check In. Upon clicking it, the database is updated and a dropdown is presented in place of the button. In the dropdown, there are locations for the user to choose, that have values of their corresponding location-number, which upon clicking update the database. The last option is labeled Check Out, and upon clicking it, the database is supposed to be updated one last time, and then red text saying Checked Out should appear.

The problem is, there multiple sets of the above process (meaning there are many Check In buttons, which turn into selects and then read Checked Out, which all work individually). So what I need is a way to pass the id of each set to the database at the same time I’m updating the database. I was thinking something like a hidden field underneath each button, that was populated with the id, and then when the Check In button was clicked, the ajax would send the hidden field with it?

Here’s my html:

<button class="checkIn">Check In</button>

<form method='post' class='myForm' action=''>
  <select name='locationSelect' class='locationSelect'>
     <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>
     <option value='CheckOut'>Check Out</option>
  </select>
</form>

and here is the jquery

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

<script type="text/javascript">
$(document).ready(function() {    
    $('.locationSelect').hide();
    $('.finished').hide();
});

$('.checkIn').click(function(){
    $e = $(this);
    $.ajax({
    type: "POST",
    url: "changeloc.php",
    data: "checkIn="+$(this).val(),
    success: function(){
      $('.checkIn').css("display","none");
              $('.locationSelect').show();        
         }
    });
});

$('.locationSelect').change(function(){
    $e = $(this);
    $.ajax({
       type: "POST",
       url: "changeloc.php",
       data: "locationSelect="+$(this).val(),
       success: function(){

       }
    });
});
$('.locationSelect option[value="CheckOut"]').click(function(){
    $e = $(this);
    $.ajax({
       type: "POST",
       url: "changeloc.php",
       data: "checkOut="+$(this).val(),
       success: function(){
       $('.locationSelect').css("display","none");
       $('.finished').show();
       alert('done');
       },
       error: function(request){
       alert(request.responseText);
       }
    });
});

</script>

I’m not sure if my solution would be viable, so please feel free to propose other solutions. If you need any other details, please just ask!

Thanks for any and all help!

  • 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-13T09:34:25+00:00Added an answer on June 13, 2026 at 9:34 am

    It is cleaner to send data as a map.. (Key : value ) pairs when sending to the server.

    Instead of this

    data: "checkIn="+$(this).val(),
    

    Try sending it this way

    data: { "checkIn" :  $(this).val() } ,
    

    EDIT

    To perform this logic you need not use a hidden input fields in the first place..
    I would prefer using HTML5 data-* attributes to get the work done.. This also passes HTML validation…

    Lets assume that the button and form are one below another.. Then you can give the button a data attribute called button-1 and the select-1 for the corresponding select..

    The HTML will look something like this..

    <button class="checkIn" data-param="button-1">Check In</button>
    
    <form method='post' class='myForm' action=''>
      <select name='locationSelect' class='locationSelect' data-param="location-1">
         <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>
         <option value='CheckOut'>Check Out</option>
      </select>
    </form>
    <div class="finished" >
        Checked Out
    </div>
    
    <button class="checkIn" data-param="location-2">Check In</button>
    
    <form method='post' class='myForm' action=''>
      <select name='locationSelect' class='locationSelect' data-param="location-2">
         <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>
         <option value='CheckOut'>Check Out</option>
      </select>
    </form>
    <div class="finished" >
        Checked Out
    </div>
    .....
    

    Javascript

    $(document).ready(function() {
        $('.locationSelect').hide();  // Hide all Selects on screen
        $('.finished').hide();        // Hide all checked Out divs on screen
    
        $('.checkIn').click(function() {
            var $e = $(this);
            var data = $e.data("param").split('-')[1] ;
            // gets the id  of button  (1 for the first button)
            // You can map this to the corresponding button in database...
            $.ajax({
                type: "POST",
                url: "changeloc.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...
                    $e.nextAll('form').first().find('.location').show();
                }
            });
        });
    
        $('.locationSelect').change(function() {
            $e = $(this);
            var data = $e.data("param").split('-')[1] ;
            // gets the id  of select (1 for the first 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
                }
            });
        });
        $('.locationSelect option[value="CheckOut"]').click(function() {
            var $e = $(this);
            var data = $e.closest('select').data("param").split('-')[1] ;
            // gets the id  of select (1 for the first select)
            // You can map this to the corresponding select in database...
            // from which checkout was processed
            $.ajax({
                type: "POST",
                url: "changeloc.php",
                data: { "checkOut" : $(this).val(), "selectid" : data},
                success: function() {
                    // Get the immediate form for the option
                    // find the first finished div sibling of form
                    // and then show it..
                    $e.closest('form').nextAll('.finished').first().show();
                    // Hide the current select in which the option was selected
                    $e.closest('.locationSelect').hide();
                    alert('done');
                },
                error: function(request) {
                    alert(request.responseText);
                }
            });
        });
    });​
    

    I have written most of the logic as comments in the code..

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

Sidebar

Related Questions

I have a couple form elements that when clicked update the database and disappear.
I have a form which has elements in a couple of divs. Based on
I have a form that has a field pulled from the database as a
I have a window form that has a couple of combo boxes. What I
Im using the bassistance form validation. I have a couple of fields that require
I have a couple Hidden form fields that are not being sent when I
We have a couple mini-applications (single Web form look-up stuff) that need to run
i have a couple questions about an idea i have to manage a form
I have been looking at a couple html/css form frameworks like Uni-Form and Formy
I have a form with two combo boxes and couple of buttons. One of

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.