javascript - Why are my checkbox and double-click functions not responsive? -


this question has answer here:

i have code making table on fly checkbox, , refreshing after minute. checkbox , double-click functions not working, , i'm not sure why. please help.

<script type='text/javascript'>   function vehicle() {     $('#vehicles').html(       <?php         $username =$_session['user_name'];         $sql = "select * gps_product gp_userid ='$username'";         $db = new dbclass($sql);         echo '"<table>';         echo '<tr>';         echo '<th>name</th>';         echo '<th>driver</th>';         echo '<th>last seen</th>';         echo '<th>follow</th>';         echo '<th>status</th>';         echo '<th>speed</th>';         echo '<th>engine</th>';         echo '<th>address</th>';         echo '</tr>';         while ($db->fetch_array()){             $timezone = $db->get('gp_timezone');             $sql2 = "select *, date_add(gm_gpstime, interval ".$timezone." hour) gpstime gps_msg             gm_imei = '" . $db->get('gp_imei') . "' , gm_event = '0' order gm_gpstime desc limit 1;";             $db2 = new dbclass($sql2);             while ($db2->fetch_array()) {                 echo '<tr id=\''.$db->get("gp_imei").'\' class=\'vehicle\'>';                 echo '<td>';                 echo $db->get("gp_name");                 echo '</td>';                 echo '<td>';                 if ($db->get("gp_sopir"))                 echo $db->get("gp_sopir");                 echo '</td>';                 echo '<td>';                 echo ago(time() - timetosecond($db2->get('gpstime'), 0));// berapa detik yang lalu                 echo '</td>';                 echo '<td>';                 echo '<center><input type=\'checkbox\' class=\'checkbox\' id=\'';                 echo $db->get("gp_imei");                 echo '\'></input></center>';                 echo '</td>';                 echo '<td>';                 $mode = cekstatusgps($db2->get('gm_accuracy'), substr($db2->get('gm_devicestate'),0,2));                  echo '<center><img src=\'status/'.$mode.'.png\' width=\'20px\' height=\'20px\'></center>';// status                 echo '</td>';                 echo '<td>';                 echo $db2->get('gm_speed').'km/h';// kecepatan                 echo '</td>';                 echo '<td><center>';                 if (substr($db2->get('gm_devicestate'),0,1) == '1'){                     $engine = 'off';                 }                 else if(substr($db2->get('gm_devicestate'),0,1) == '2'){                     $engine = 'on';                 }                 echo $engine;// engine on/off                 echo '</center></td>';                 echo '<td>';                 if ($db->get('gp_rgeo') == 1) {                     $posisi = parse_location($db2->get('jalan'). "," . $db2->get('kota'). "," . $db2->get('kabupaten'). "," . $db2->get('propinsi'). "," . $db2->get('negara'). "," . $db2->get('landmark'));                 }                  else{                     $posisi = result_location($db2->get('gm_lat'),$db2->get('gm_lng'));                 }                 echo $posisi;// alamat                 echo '</td>';                 echo '</tr>';             }         }         echo '</table>"';         ?>     );   }  $(document).ready(function() {     $('#map').html('<object data="map.php?user=<?php echo $_session['       user_name ']?>" width="100%" height="100%">');     $(function() {       vehicle();       setinterval(vehicle, 60000);     });     $('.checkbox').change(function() {       if (this.checked) {         $('#map').html('<object data="map.php?imei=' + this.id + '" width="100%" height="100%">');         $('.checkbox').not(this).prop('checked', false);       } else {         $('#map').html('<object data="status.php?user=<?php echo $_session['           user_name ']?>" width="100%" height="100%">');       }     });     $('.vehicle').dblclick(function() {       $('#status').html('<object data="status.php?imei=' + this.id + '" width="100%" height="100%">');     });   }); </script> 

i want refresh vehicle div when use coding checkbox , double-click functions not working.

since added elements page via echo of php, have bind them again .on()

so instead of $('.checkbox').change(function(){});,

change $('#vehicles').change('change', '.checkbox', function(){});

and add change echo.

note make php messy, suggest making binding js function, calling function on echo


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -