javascript - Chained select boxes with jquery/php/database not working -


it seems chained selects accomplished json, unfortunately it's more convenient me use database accomplish this. it's there, reason second select box not loading properly. instead it's loading entire html page it's on , i'm not sure why.

here's i've got (note make_list() , model_list() functions built return array appropriate respective criteria)

the js:

$(document).ready(function(){     $("select#type").attr("disabled","disabled");     $("select#category").change(function(){         $("select#type").attr("disabled","disabled");         $("select#type").html("<option>loading...</option>");         var id = $("select#category option:selected").attr('value');         $.post("select_type.php", {id:id}, function(data){             $("select#type").removeattr("disabled");             $("select#type").html(data);         });     });     $("form#select_form").submit(function(){         var cat = $("select#category option:selected").attr('value');         var type = $("select#type option:selected").attr('value');         if(cat>0 && type>0)         {             var result = $("select#type option:selected").html();             $("#result").html('your choice: '+result);         }         else         {             $("#result").html("you must choose 2 options!");         }         return false;     }); }); 

the html/php:

<form id="select_form">   <div class="clearfix">     <select id="category">         <option value="">any</option>         <?php foreach ( make_list() $make ) { ?>           <option value="<?php echo $make ?>"><?php echo $make ?></option>         <?php } ?>       </select>     </div>      <div class="clearfix">       <select id="type">         <option value="">any</option>       </select>   </div> </form> 

when first select changed jquery should @ file in same folder called 'select_type.php'. here's what's in file (strangely $_post['id'] doesn't seem appending file either, despite being created in js):

foreach ( model_list($_post['id']) $model ) {     echo '<option value="'.$model.'">'.$model.'</option>'; } 

i've been using resource project: http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/ , it's gotten me of way, unfortunately data doesn't seem loading second select box.

thanks looking!

okay, figured 1 out. helps same problem in future.

the call file, select_type.php incorrect. call must absolute rather relative. since i'm using wordpress changed line this:

$.get("<?php echo get_template_directory_uri() . '/includes/select-model.php'; ?>", {id:id}, function(data){ 

you'll notice changed $.post $.get. i'm not sure why post wasn't working, seems work fine. i'm retrieving values in select_type.php using $_get['id'].

hope helps someone!


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -