Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--FILE: latihan2.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Latihan AJaX</title>
- </head>
- <body>
- <form>
- Kota
- <select id='kota' name='kota'>
- <option value=''>--pilih kota --</option>
- <?php
- $kota=array('1'=>'Jakarta','Bandung','Semarang','Yogyakarta','Surabaya','Denpasar');
- foreach($kota as $val=>$text) echo "<option value='{$val}'>{$text}</option>";
- ?>
- </select><br>
- bioskop <select id='bioskop' name='bioskop'><option value=''>--pilih bioskop --</option></select><br>
- studio <select id='studio' name='studio'><option value=''>--pilih studio --</option></select><br>
- <input type='submit' value='kirim'>
- </form>
- </body>
- <script
- src="https://code.jquery.com/jquery-1.12.4.min.js"
- integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
- crossorigin="anonymous">
- </script>
- <script>
- $(document).ready(function(){
- $('#kota').change(function(){
- $.post(
- 'bioskop_ajax.php',
- {'kota':$(this).val()},
- function(data){
- $('#bioskop').html(data);
- }
- );
- });
- $('#bioskop').change(function(){
- $.post(
- 'studio_ajax.php',
- {'bioskop':$(this).val()},
- function(data){
- $('#studio').html(data);
- }
- );
- });
- });
- </script>
- </html>
- //-- FILE : bioskop_ajax.php
- <?php
- if(isset($_POST['kota'])){
- $data=array(
- '1'=>array('1.1'=>'Gading IMAX','1.2'=>'Gandaria IMAX','1.3'=>'Gading PREMIERE'),
- '2'=>array('2.1'=>'Ciwalk PREMIERE','2.2'=>'Braga XXI'),
- '3'=>array('3.1'=>'Citra XXI','3.2'=>'Paragon XXI'),
- '4'=>array('4.1'=>'Ambarukmo PREMIERE','4.2'=>'Jogja City PREMIERE'),
- '5'=>array('5.1'=>'Tunjungan 5 IMAX','5.2'=>'Grand City PREMIERE'),
- '6'=>array('6.1'=>'Beachwalk PREMIERE','6.2'=>'Level21 PREMIERE'),
- );
- $hasil="<option value=''>--pilih bioskop--</option>";
- foreach($data[$_POST['kota']] as $id=>$bioskop) $hasil.="<option value='{$id}'>{$bioskop}</option>";
- echo $hasil;
- }
- //-- FILE : studio_ajax.php
- <?php
- if(isset($_POST['bioskop'])){
- $data=array(
- '1.1'=>array('1.1.1'=>'first','1.1.2'=>'second'),
- '1.2'=>array('1.2.1'=>'first','1.2.2'=>'second','1.2.3'=>'third'),
- '1.3'=>array('1.3.1'=>'first','1.3.2'=>'second'),
- '2.1'=>array('2.1.1'=>'first','2.1.2'=>'second'),
- '2.2'=>array('2.2.1'=>'first','2.2.2'=>'second'),
- '3.1'=>array('3.1.1'=>'first','3.1.2'=>'second','3.1.3'=>'third'),
- '3.2'=>array('3.2.1'=>'first','3.2.2'=>'second'),
- '4.1'=>array('4.1.1'=>'first','4.1.2'=>'second','4.1.3'=>'third'),
- '4.2'=>array('4.2.1'=>'first','4.2.2'=>'second','4.2.3'=>'third'),
- '5.1'=>array('5.1.1'=>'first','5.1.2'=>'second'),
- '5.2'=>array('5.2.1'=>'first','5.2.2'=>'second'),
- );
- $hasil="<option value=''>--pilih studio--</option>";
- foreach($data[$_POST['bioskop']] as $id=>$studio) $hasil.="<option value='{$id}'>{$studio}</option>";
- echo $hasil;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement