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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:51:05+00:00 2026-06-11T13:51:05+00:00

I have a jQuery/AJAX function that when triggered from a <select> menu change posts

  • 0

I have a jQuery/AJAX function that when triggered from a <select> menu change posts data to a php query and returns results. The results are placed in the <td><label class=count> on the same row as the <select> menu in my table. The function works just fine when the select menu is changed but I also want to trigger this function on page load. I have tried using .trigger(change); at the end of my code but all that does is place the results (2 in this case because there only two table rows) in the <td><label class=count> on the last row instead of placing the result in that cell of the parent row. Can someone help me get the function to run on page load, but the results in the <td><label class=count> of the same row as the select menu that triggered the result?

Here is jQuery:

<script type="text/javascript"> 
$(document).ready(function(){

$('.typeval').change(function(){
    var movement    =  $(this).val();
    var client_id   = $(this).parent().siblings().find('.clientval').val();
    var class_id    = <? echo $class_id; ?>;
        $count      = $(this).parents('tr').find('label.count');

$.ajax({ 
  type: "POST",
  url: "movement_count.php",
  data: {movement:movement, client_id:client_id, class_id:class_id},
  dataType: "json", 
  success:(function(output) {

      $.each(output, function(index, value){
      //alert(value);
      $count.append(output[index]);
      }) // each

   }) // success

}); // ajax

  }); // .typeval

});  // document

</script>   

Here is part of the HTML table:

 <tr>
    <td><input type="hidden" name="client_id[]" class="clientval" value="1"></td>
    <td><input type="hidden" name="order[]" value="1A">1A</td>
    <td><select name="movement[]" width=200 class="typeval"></select></td>
    <td><input type="hidden" name="rest[]" value="Rest">Rest</td>
    <td><label class="count"></label></td>
</tr>

<tr>
   <td><input type="hidden" name="client_id[]" class="clientval" value="8"></td>
   <td><input type="hidden" name="order[]" value="1A">1A</td>
   <td><select name="movement[]" width=200 class="typeval"></select></td>
   <td><input type="hidden" name="rest[]" value="Rest">Rest</td>
   <td><label class="count"></label></td>
</tr>

Here is the movement_count.php

<?php

include('core/init.php');
protect_page();


$class_id = $_POST['class_id'];


if (isset($_POST['client_id'])){
$xmovement = x_move_performed($class_id, $_POST['client_id'], $_POST['movement']);

    echo json_encode ($xmovement);   
} // isset      


?>

Here is the php function that queries the db and returns a number(COUNT)

function x_move_performed($class_id, $client_id, $movement){
$class_id = (int)$class_id;
$client_id = (int)$client_id;

$query = "SELECT COUNT(`movement`) FROM `completed_movements` WHERE `class_id` = $class_id AND `client_id` = $client_id AND `movement` = '$movement'";
$res = mysql_query($query);
$result = mysql_fetch_assoc($res);
return $result;
}
  • 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-11T13:51:06+00:00Added an answer on June 11, 2026 at 1:51 pm

    try to make the ajax synchronous:

    async: false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery-ajax function that sends data to a php script and the
I have a jQuery AJAX data grid that loads a list of elements from
I have a jquery function that takes the data from the 3rd column of
I have a jQuery AJAX function like this: $.ajax({ url: 'crud/clients.php', dataType: 'json', type:
I have written a simple jQuery.ajax function which loads a user control from the
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
I have the following jQuery statement: $.ajax({ type: POST, url: db.php, data: word=+ tmpWord,
I use Wordpress, PHP, jQuery and AJAX. I can get data from PHP through
I have an jquery ajax success function which uses a template to put json

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.