php - Retrieve subcategory selection option via Ajax based on category selection -


like title says, i'm trying populate 1 selection element based selection of another.

i've come code, works when i'm retrieving records db live search not firing here, appreciated:

$(document).ready(function() {        function search() {         var query_value = $('select#category_id').val();          if(query_value !== ''){             $.ajax({                 type: "post",                 url: "ajax_php/subcategory.php",                 data: { category: query_value},                 cache: false,                 success: function(html){                     $("select#subcateogry").html(html);                 }             });         }return false;         }  }); 

php code in short, i'm catching post variable, doing query , echoing:

echo "<option value='".$result['id']."'>".$result['subcategory']."</option>"; 

html:

<p>     <label>item subcategory:</label>     <select id='subcategory' name='subcategory'>      </select> </p> 

is there obvious mistake i'm missing here?

thanks

you can call ajax method on onchange event of category section have made changes in code please have success:functon(data)//html

$('select#category_id').onchange(function(){   search(); });    function search() {     var query_value = $('select#category_id').val();     if(query_value !== ''){         $.ajax({             type: "post",             url: "ajax_php/subcategory.php",             data: { category: query_value},             cache: false,             success: function(data){                 $("select#subcateogry").html(data);             }         });     }return false;     } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -