Created
March 14, 2014 02:51
-
-
Save ruliarmando/9541337 to your computer and use it in GitHub Desktop.
ajax-combo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $data = array( | |
| 'hendra' => 78, | |
| 'nina' => 90, | |
| 'budi' => 80, | |
| 'chandra' => 77, | |
| 'anisa' => 92, | |
| 'dedi' => 90, | |
| ); | |
| if(isset($_POST['nama'])) | |
| { | |
| $nama = $_POST['nama']; | |
| if(isset($data[$nama])) | |
| { | |
| echo $data[$nama]; | |
| exit(); | |
| } | |
| } | |
| ?> | |
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Testing Ajax ComboBox</title> | |
| <script src="jquery.js"></script> | |
| <script> | |
| $(document).ready(function(){ | |
| $('#select_nama').change(function(){ | |
| $.ajax({ | |
| url: window.location.pathname, | |
| type: 'post', | |
| data: {'nama' : $(this).val()}, | |
| dataType: 'text', | |
| success: function(data){ | |
| $('#txt_nilai').val(data); | |
| } | |
| }); | |
| }); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <select name="nama" id="select_nama"> | |
| <option value="">--pilih--</option> | |
| <?php foreach($data as $k => $v): ?> | |
| <option value="<?php echo $k; ?>"><?php echo $k; ?></option> | |
| <?php endforeach; ?> | |
| </select><br /> | |
| <input type="text" name="nilai" id="txt_nilai" /> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment