Advertisement
cdsatrian

select n show

Oct 12th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Select Worksheet</title>
  5.     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  6.   <head>
  7.   <body>
  8.   <select name="kodeworksheet"­ id="pilih"­ class="easyui-valida­­tebox" required="true">
  9.   <?php
  10.   include("../koneksi/conn.php");
  11.   $sql="SELECT kodeworksheet FROM tmworksheet ORDER BY kodeworksheet";
  12.   $query = mysql_query($sql);
  13.   while($row=mysql_fetch_object($query))
  14.   {
  15.     echo "<option value=\"".$row->kodeworksheet."\">".$row->kodeworksheet."</option>\n";
  16.   }
  17.   ?>
  18.   </select>
  19.   <input type="text" id="biayaworksheet" readonly="readonly" />
  20.   <input type="text" id="namaworksheet" readonly="readonly" />
  21.   <input type="text" id="keterangan" readonly="readonly" />
  22.   <script type="text/javascript">
  23.   $('#pilih').change(function(){
  24.     $.ajax({
  25.       type=:'POST',
  26.       datatype:'json',
  27.       url:'proses.php',
  28.       data:'id='+$(this).val(),
  29.       success:function(html){
  30.         $('#biayaworksheet').val(html.biaya);
  31.         $('#namaworksheet').val(html.nama);
  32.         $('#keterangan').val(html.keterangan);
  33.       }
  34.     });
  35.   });
  36.   </script>
  37.   </body>
  38. </html>
  39.  
  40. //========= file: proses.php =================
  41. <?php
  42.   $id=isset($_POST['id'])?$_POST['id']:"";
  43.   include("../koneksi/conn.php");
  44.   $where=!empty($id)" WHERE kodeworksheet='".$id."' ":"";
  45.   $sql="SELECT biayaworksheet,namaworksheet,keterangan FROM tmworksheet ".$where." ORDER BY kodeworksheet";
  46.   $query = mysql_query($sql);
  47.   if($query->mysql_num_rows>0){
  48.     $row=mysql_fetch_object($query);
  49.     $result=array("biaya"=>$row->biayaworksheet,"nama"=>$row->namaworksheet,"keterangan"=>$row->keterangan);
  50.   }else{
  51.     $result=array("biaya"=>"","nama"=>"","keterangan"=>"");
  52.   }
  53.   return json_encode($result);
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement