Advertisement
joris

jQuery Append

Oct 10th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Add Option Dinamix</title>
  6. <link type="text/css" rel="stylesheet" href="fb-1.css" />
  7. <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
  8. <script>
  9. $(document).ready(function() {
  10.     var Pertama = {
  11.         val1 : 'Pilihan Keren',
  12.         val2 : 'Pilihan Cadas',
  13.         val3 : 'Pilihan Ganteng',
  14.         val4 : 'Pilihan Cool'
  15.     };
  16.     var Kedua = {
  17.         val1 : 'Pilihan Jelek',
  18.         val2 : 'Pilihan Modar',
  19.         val3 : 'Pilihan Ancur',
  20.         val4 : 'Pilihan Rusak'
  21.     };
  22.     var mySelect = $('#kedua');
  23.    
  24.     $("#pertama").change(Pertama, function(val, text) {
  25.         $("#kedua").html("");
  26.         if ($(this).find('option:selected').text() == 'Keren'){
  27.             AmbilPertama()
  28.         }else{
  29.             AmbilKedua()
  30.         }
  31.     });
  32.    
  33.  
  34.  
  35. function AmbilPertama(){
  36.     $.each(Pertama, function(val, text) {
  37.             mySelect.append(
  38.                 $('<option></option>').val(val).html(text)
  39.             );
  40.         });
  41. }
  42.  
  43. function AmbilKedua(){
  44.     $.each(Kedua, function(val, text) {
  45.             mySelect.append(
  46.                 $('<option></option>').val(val).html(text)
  47.             );
  48.         });
  49. }
  50.  
  51. });
  52. </script>
  53. </head>
  54.  
  55. <body>
  56. <select id="pertama" class="ComboBox">
  57.   <option value="0">- Pilih Data -</option>
  58.   <option value="1">Keren</option>
  59.   <option value="2">Jelek</option>
  60. </select>
  61. <br />
  62. <select id="kedua" class="ComboBox"></select>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement