php - why my script doesn't get value that I purpose -


in web there table content give static value this

<?php include 'config/koneksi.php'; ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>lay out penempatan produk uht area gudang rak a-f</title> <link rel="icon" href="http://localhost/wifi/images/rsup.png"> <link rel="stylesheet" type="text/css" href="css/popup-window.css" media="screen">  <script type="text/javascript" src="js/popup-window.js"></script> <script type="text/javascript" src="js/jquery-1.8.3.js"></script>    <script>     function setvalue(values) {     document.getelementbyid('posisi').value = values; } </script>  <script type="text/javascript"> var htmlobjek; $(document).ready(function(){   //apabila terjadi event onchange terhadap object <select id=pid>   $("#pid").change(function(){     var pid = $("#pid").val();      $.ajax({         url: "ambilnamaproduk.php",         data: "pid="+pid,         cache: false,         success: function(data){         $("#pname").val(data);         }         });     });   }); </script>  <script> var = $("#mytd").val();     alert(i); </script>  <script type="text/javascript"> var htmlobjek;  $(document).ready(function () { var = $("#mytd").val();       $.ajax({              url: "cek.php",              type:'post'              data: "i="+i,              cache: false,              success: function (data) {                  $("#cek").val(data);              }          });             });  var k = $("#cek").val(); if(k = "0"){  $(document).ready(function () {                  $(".data").css("background-color", "#00cc00");//green                  });                  }     else{  $(document).ready(function () {                  $(".data").css("background-color", "#ff0000");//red                  }); }                   </script>  </head> <body> <div> <input id="cek" name="cek" type="text" />  <table width="1023" border="1">   <tr>     <th colspan="2">a1</th>     <th colspan="2">a2</th>     <th colspan="2">a3</th>     <th colspan="2">a4</th>     <th colspan="2">a5</th>     <th colspan="2">a6</th>     <th colspan="2">a7</th>     <th colspan="2">a8</th>     <th colspan="2">a9</th>   </tr>   <tr>     <td class="data"> <div align="center"> <input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down', parent : this, width : '270px' });setvalue(this.value);" id="mytd" name="mytd" value="a1.4" /></div></td>     <td class="data"><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="a1.8" /></div></td>     <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="a2.4" /></div></td>     <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="a2.8" /></div></td>     <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="a3.4" /></div></td>     <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="a3.8" /></div></td>      <td><div align="center">a4.4</div></td>     <td><div align="center">a4.8</div></td>     <td><div align="center">a5.4</div></td>     <td><div align="center">a5.8</div></td>     <td><div align="center">a6.4</div></td>     <td><div align="center">a6.8</div></td>     <td><div align="center">a7.4</div></td>     <td><div align="center">a7.8</div></td>     <td><div align="center">a8.4</div></td>     <td><div align="center">a8.8</div></td>     <td><div align="center">a9.4</div></td>     <td><div align="center">a9.8</div></td>   </tr>   <tr>     <td><div align="center">a1.3</div></td>     <td><div align="center">a1.7</div></td>     <td><div align="center">a2.3</div></td>     <td><div align="center">a2.7</div></td>     <td><div align="center">a3.3</div></td>     <td><div align="center">a3.7</div></td>     <td><div align="center">a4.3</div></td>     <td><div align="center">a4.7</div></td>     <td><div align="center">a5.3</div></td>     <td><div align="center">a5.7</div></td>     <td><div align="center">a6.3</div></td>     <td><div align="center">a6.7</div></td>     <td><div align="center">a7.3</div></td>     <td><div align="center">a7.7</div></td>     <td><div align="center">a8.3</div></td>     <td><div align="center">a8.7</div></td>     <td><div align="center">a9.3</div></td>     <td><div align="center">a9.7</div></td>   </tr>   <tr>     <td><div align="center">a1.2</div></td>     <td><div align="center">a1.6</div></td>     <td><div align="center">a2.2</div></td>     <td><div align="center">a2.6</div></td>     <td><div align="center">a3.2</div></td>     <td><div align="center">a3.6</div></td>     <td><div align="center">a4.2</div></td>     <td><div align="center">a4.6</div></td>     <td><div align="center">a5.2</div></td>     <td><div align="center">a5.6</div></td>     <td><div align="center">a6.2</div></td>     <td><div align="center">a6.6</div></td>     <td><div align="center">a7.2</div></td>     <td><div align="center">a7.6</div></td>     <td><div align="center">a8.2</div></td>     <td><div align="center">a8.6</div></td>     <td><div align="center">a9.2</div></td>     <td><div align="center">a9.6</div></td>   </tr>   <tr>     <td><div align="center">a1.1</div></td>     <td><div align="center">a1.5</div></td>     <td><div align="center">a2.1</div></td>     <td><div align="center">a2.5</div></td>     <td><div align="center">a3.1</div></td>     <td><div align="center">a3.5</div></td>     <td><div align="center">a4.1</div></td>     <td><div align="center">a4.5</div></td>     <td><div align="center">a5.1</div></td>     <td><div align="center">a5.5</div></td>     <td><div align="center">a6.1</div></td>     <td><div align="center">a6.5</div></td>     <td><div align="center">a7.1</div></td>     <td><div align="center">a7.5</div></td>     <td><div align="center">a8.1</div></td>     <td><div align="center">a8.5</div></td>     <td><div align="center">a9.1</div></td>     <td><div align="center">a9.5</div></td>   </tr> </table> </div>  <div   class="popup_window_css" id="sample"/> <table class="popup_window_css"/> <tr    class="popup_window_css"/> <td    class="popup_window_css"/> <div   class="popup_window_css_head"><img src="images/close.gif" alt="" width="9" height="9" />aksi</div> <div   class="popup_window_css_body"/><div style="border: 1px solid #808080; padding: 6px; background: #ffffff;"/> <form method="post" action="aksi.php"/> <table>     <tr>      <td> werehouse product </td>      <td><select name="wp">         <option selected>- jenis werehouse -</option>         <?php         $q = mssql_query("select whsname tblspdmstwarehouseproduct order whsid");           while ($r = mssql_fetch_array($q)){         echo "<option value=$r[whsname]>$r[whsname]</option>";         }         ?> </select> </td>     <tr>      <td> posisi</td>      <td> <input type='text' name='posisi' id='posisi' readonly/></td>     </tr>     <tr>      <td> product id</td>      <td> <select name="pid" id="pid">         <option selected = "selected" >- produk id -</option>             <?php             $q = mssql_query("select productid tblmstproduct order productid");               while ($r = mssql_fetch_array($q)){             echo "<option value=$r[productid]>$r[productid]</option>";         }?>         </select>      </td>     </tr>     <tr>      <td> product name</td>      <td ><input type="text" id="pname" name="pname" size="65" readonly/>      </td>     </tr>     <tr>      <td> production date</td>      <td > <input type='text' name="tgl" /></td>     </tr>     <tr>         <td colspan='2' align='center'>          <input type='submit' value= 'save'>           <input type='button' value='view' onclick="javascript:ajax_post();"/>          </td>     </tr> </table> </from> <div class="popup_window_css_foot"> </div> </body> </html> 

and use jquery selector value , use ajax execute value this

 var htmlobjek;      $(document).ready(function () {          var = $("td").find("td.data").val();           $.ajax({                  url: "cek.php",                  data: "i",                  cache: false,                  success: function (data) {                      $("#cek").val(data);                  }              });           }); 

in cek.php of course this

<?php $posisi =  $_post[i];  $val = mssql_num_rows(mssql_query("select*from tbltrnproduct posisi = '$posisi'"));  echo"$val"; ?> 

according answer before, yes work. in single table. have checked html structure(it's okay). after modified complex table same case happen again.

after <td class="data"> forgot </tr> .

$(document).ready(function(){      function setvalue(values) {         $('#posisi').val(values);     }      var htmlobjek;     //apabila terjadi event onchange terhadap object <select id=pid>     $("#pid").change(function(){         var pid = $("#pid").val();         $.ajax({             url: "ambilnamaproduk.php",             data: "pid="+pid,             cache: false,             success: function(data){                 $("#pname").val(data);             }         });     });      var = $("tr").find("td.data").attr('value');     $.ajax({          url: "cek.php",          type:'post'          data: {"data": i},          cache: false,          success:           function (data) {              $("#cek").val(data);          }     });      var k = $("#cek").val();     if(k = "0"){         $(".data").css("background-color", "#00cc00");//green     }     else {         $(".data").css("background-color", "#ff0000");//red     }  }); 

in cek.php 'i' should available $_post['data'].

fyi: if have multiple rows value, or multiple tables value in rows of tables should write code different. please see this jsfiddle.

however if there lot of values, there lot of ajax calls. better solution add value hidden input. please see this jsfiddle.

hope helped out.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -