php - jQuery val() returning previously selected element value -


i have javascript function handle dynamic ids table.

table:

<table border = "0" width = "95%"  class = "table table-striped table-bordered" id = "tblinfochecks">     <thead>         <tr>             <th><center>#</center></th>             <th><center>category</center></th>             <th><center>name</center></th>             <th><center>date</center></th>             <th><center>due date</center></th>             <th><center>allocation</center></th>             <th><center>status</center></th>             <th><center>tat</center></th>             <th><center>action</center></th>         </tr>     </thead>     <tbody>         <?php                                $q = "select * checks candidate_id = '$case_id' , client_id = '$client_id'";             $res = mysql_query($q);             $numr = mysql_numrows($res);             $y = 0;              while($y < $numr){                  $m = $y + 1;                 $check_id = mysql_result($res, $y, "case_id");                           $check_name = mysql_result($res, $y, "check_name"); //hidden                 $check_cat = mysql_result($res, $y, "check_category"); //hidden                 $elements = mysql_result($res, $y, "elements"); //hidden                  //verified information -- hidden                 $ver_status = mysql_result($res, $y, "ver_status");                 $ver_remarks = mysql_result($res, $y, "ver_remarks");                 $ver_action = mysql_result($res, $y, "ver_action");                 $overall_status = mysql_result($res, $y, "overall_status");                  $check_date = mysql_result($res, $y, "date_to_process");                 $check_due_date = mysql_result($res, $y, "due_date");                 $ver_id = mysql_result($res, $y, "verifier_id");                 $check_status = mysql_result($res, $y, "status");                   //hidden elements                 echo '<input type = "text" style = "" id = "txtinfocheckid'.$y.'" value = "'.$check_id.'" />';                 echo '<input type = "text" style = "" id = "txtinfocheckname'.$y.'" value = "'.$check_name.'" />';                 echo '<input type = "text" style = "" id = "txtinfocheckcat'.$y.'" value = "'.$check_cat.'" />';                  echo '<input type = "text" style = "" id = "txtinfocheckelements'.$y.'" value = "'.$elements.'" />';                 echo '<input type = "text" style = "" id = "txtinfocheckverstatus'.$y.'" value = "'.$ver_status.'" />';                 echo '<input type = "text" style = "" id = "txtinfocheckverremarks'.$y.'" value = "'.$ver_remarks.'" />';                 echo '<input type = "text" style = "" id = "txtinfocheckveraction'.$y.'" value = "'.$ver_action.'" />';                 echo '<input type = "text" style = "" id = "txtinfocheckoverallstatus'.$y.'" value = "'.$overall_status.'" />';                  //get verifier name                 $ver = "select name employees id = '$ver_id'";                 $ver_res = mysql_query($ver);                 $ver_numr = mysql_numrows($ver_res);                 if($ver_numr != 0){                     $ver_name = mysql_result($ver_res, 0 ,0);                 }                   //compute tat                 $check_date_sec = strtotime($check_date);                 $today = strtotime(date("m/d/y", time()));                 $tat = $today - $check_date_sec;                 $time_arr = secondstotime($tat);                 $final_tat = $time_arr["d"]; //tat                  echo '                     <tr>                         <td><center>'.$m.'</center></td>                         <td><center>'.$check_cat.'</center></td>                         <td><center>'.$check_name.'</center></td>                         <td><center>'.$check_date.'</center></td>                         <td><center>'.$check_due_date.'</center></td>                         <td><center>'.$ver_name.'</center></td>                         <td><center>'.$check_status.'</center></td>                         <td><center>'.$final_tat.'</center></td>                         <td><center><a href = "javascript: void(0);" id = "viewinfocheckelements'.$y.'">view elements</a></center></td>                     </tr>                                    ';                                $y++;             }          ?>     </tbody>     <tfoot>         <tr>             <th><center>#</center></th>              <th><center>category</center></th>             <th><center>name</center></th>             <th><center>date</center></th>             <th><center>due date</center></th>             <th><center>allocation</center></th>             <th><center>status</center></th>             <th><center>tat</center></th>             <th><center>action</center></th>         </tr>     </tfoot> </table> 

js

var rowcount_infochecks = $('#tblinfochecks >tbody >tr').length;                                                                                     for(var = 0; < rowcount_infochecks; i++) {viewinfochecks(i);} 

viewinfochecks:

function viewinfochecks(place){         $('#viewinfocheckelements'+place).livequery(function(){             $('#viewinfocheckelements'+place).live("click", function(e){                 var check_id = $('#txtinfocheckid'+place).val();             alert(check_id);                                 var check_name = $('#txtinfocheckname'+place).val();                                 var check_cat = $('#txtinfocheckcat'+place).val();                 var check_elem = $('#txtinfocheckelements'+place).val();                 var ver_status = $('#txtinfocheckverstatus'+place).val();                 var ver_remarks = $('#txtinfocheckverremarks'+place).val();                 var ver_action = $('#txtinfocheckveraction'+place).val();                 var overall_status = $('#txtinfocheckoverallstatus'+place).val();                   $.post(                     "posts/view-check-elements.php",                     {                         check_name : check_name,                         check_cat : check_cat,                         check_elem : check_elem,                         ver_status : ver_status,                         ver_remarks : ver_remarks,                         ver_action : ver_action,                         overall_status : overall_status                     },                     function(data){                         $('#popupviewinfochecks').html(data);                         $('#popupviewinfochecks').lightbox_me({                             centered: true                         });                         e.preventdefault();                     }                 );              });         });     } 

every time load table div element using $('#').html(data); loaded , try unhide hidden values , element values placed. when access through $('#').val() , alert values becomes inconsistent. when access element previous selected value 1 appearing assumption is related browser when try clear cache still appearing think problem code.

example:

  • the value of input selector id myid0 "boy";
  • i alert value of myid0 , value boy correct
  • i try load table again , query different values boy becomes girl
  • i alert value of same selector myid0, value still boy , newly assigned value(girl) not recognized selector myid0.val();

might sort of issue due selector / time load html. i'd try this:

function(data){     var $popupviewinfocheck = $('#popupviewinfochecks');     $popupviewinfocheck.html(data);     $popupviewinfocheck.lightbox_me({         centered: true     });     e.preventdefault(); } 

..and way, should assigning selectors variable when possible performance reasons.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -