Advertisement
cdsatrian

autocomplete return id

Apr 19th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.80 KB | None | 0 0
  1. <?php
  2. $sql = mysql_query("SELECT id_jabatan, nm_jabatan FROM tbjabatan");
  3. $options='';
  4. while($j = mysql_fetch_array($sql)) {
  5.   $options.= '{value:'.$j['id_jabatan'].',label:"'.$j['nm_jabatan'].'"},';
  6. }
  7. ?>
  8. <script>
  9. $(function() {
  10.   var availableJab = [<?php echo $options;?>];
  11.   $("#nmjab").autocomplete({
  12.     source: availableJab,
  13.     focus: function(event, ui) {
  14.       $("#nmjab").val(ui.item.label);
  15.       return false;
  16.     },
  17.     select: function (event, ui) {
  18.       $("#nmjab").val(ui.item.label);
  19.       $("#idjab").val(ui.item.label);
  20.       return false;
  21.     }
  22.   });
  23.  
  24. });
  25. </script>
  26. <label for="idjab">Jabatan</label> :
  27. <!-- id jabatan -->
  28. <input type="text" name="nmjab" id="nmjab" size="20px" class="inputxt" placeholder="Ketik Jabatan..." />
  29. <input type="hidden" name="idjab" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement