JQuery:.. Değişkendir gösterilmesini değil, değiştirmek yük

0 Cevap php

Ben dinamik Pulldowns kuruyorum: seçin # kategorisinde seçim seçin # Subcat içeriğini bildirir.

Bu seçin # kategori için html:

<select name="category" id="category">
    <option>Click Here to choose a category</option>
           <?php foreach ($categories as $key => $category) { ?>
    <option value="<?php echo $key ?>"><?php echo $category ?></option>
           <?php } ?>         
</select>

<select name="subcat" id="subcat">
    <option>&lt;-- First Choose a Category</option>                           
</select>

Bu jQuery ifadedir:

$(document).ready(function(){
    $("select#category").change(function(){
        $("select#subcat").load("subcats.php",{ id: $(this).val(), ajax: 'true'});
    });
});

Bu subcats.php olduğunu:

<?php
      //source of categories
      include("config.php") ;
      //initiate option list
      $options =  '<option value="">Choose a Sub-category</option>'."\n" ;
      if(!empty($_GET["id"])) {
      //iterate through the categories
      foreach ($categories as $key => $category) {
      if ($_GET["id"] == $key) {
      //select the data source
      $subcats = file('subcat/'.$key.'.dat', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ;
      natsort($subcats);
      //create the rest of the option list
          foreach ($subcats as $subcat) {
          list ($subname,$subkey ) =explode ("\t", $subcat) ;
           $options .=  '<option value="'.$subkey.'">'.$subname.'</option>'."\n" ;
      }
      echo  $options ;   
          }
      }
      }  else {
      // if no variable given provide option list as error check
      echo  '<option value="">&lt;-- Choose a Category First</option>
      <option value="">Foo Bar</option>'."\n" ;   
          }
      ?>

My understanding is that id: $(this).val() provides the selected option from select#category for use in the php document; am I off base here? Really, if I'm reading the docs right, I shouldn't even need the , { id: $(this).val(), ajax: 'true'} bit the ajax request .load is working, because the error check menu items appear in the select#subcats.

Ancak, görünen hepsi: değişken yoluyla almak gibi görünmüyor ...

Li'l burada yardım? Şimdiden teşekkürler!

0 Cevap