2014-10-20 58 views
0

我想创建一个产品,类别 - 子类别 - 子子类别 3下拉菜单为例如:类别健康,美丽和个人==>子类别化妆= => sububcategory- Eyeliner。主要类别填充正确和子类别应根据用户选择填充,如果他们选择健康,美容个人护理,然后它应该填充子类别。我写了一个Ajax更改函数动态获取值用户并重新加载页面,但是它接收到来自用户的值,但是子类别没有填充,在下面的代码片段中,如果cat_id被改变,则该函数将被触发,但是,即使用户,cat_id也没有收到任何值请在主要类别中选择一个选项请帮助我或给我建议我需要做些什么来解决这个问题......Ajax变化(功能()没有触发

$(document).ready(function(){ 

$('#cat_id').change(function() 
{ 

     var categoryId = $(this).val(); 
     // alert(categoryId); 


    $.post("<?php echo DEFAULT_URL ?>/addProduct/ajax_getSubCategory", {categoryId: categoryId}, function(data) 

    { 

     if (data) { 

      // $('#cat_id').html(data); 

      $('#subcat_id').html(data); 

      $('#subsubcat_id').html('<option>Select Sub Sub Category</option>'); 

       } 

    }); 

}); 

}); 

回答

0

这可能是问题的根源:

变化:

var categoryId = $(this).val(); 

到:

var categoryId = $(this).find(':selected').val(); 

在你正试图获得的价值的那一刻下拉而不是选定的值。

+0

感谢您的答复。我试过这个,但它不工作。 cat_id不会改变,它仍然接收空值。如果cat_id被改变,那么只有改变函数才会被触发。我不知道该怎么做...... – sam 2014-10-20 15:34:20

+0

你能发布你的html吗?更改功能是不是你想要触发的唯一的事情? – 2014-10-20 15:40:06

+0

我想在更改cat_id时触发更改功能。但是,当我选择主类别值时,cat_id没有收到任何值。 – sam 2014-10-20 19:54:36

0

这是HTML代码我已经使用下拉形式...
/addProduct命令”是enctype = '的multipart/form-data的'>

           <fieldset> 

                <legend>Category Information</legend> 

                <div class="required"> 

                 <label for="category">Main Category 

                  <font color="red" title="This field is required for registration.">*</font></label> 

                 <?php if(isset($merchantData->membership_package) && $merchantData->membership_package==2) 

                  $categoryId=1; 

                 if(isset($categoryId) && $categoryId!='') 

              $whereCondition="category_id='".$categoryId."' && is_active='1' && parent_id='0' order by category_name"; 

                 else 

                  $whereCondition="is_active='1' && parent_id='0' order by category_name"; 

                 ?> 

                 <?php 

                 echo $obj_category->selectBox('cat_id', 'Select Category', 'category_id', 'category_name', isset($cat_id) ? $cat_id :"",$whereCondition, 'class="validate[required]"'); 


                 ?> 



                <div class="clear"></div> 

                <small>Please select the best combination of category and sub-categories for your product</small> 

                </div> 

                <div class="required"> 

              <label for="sub_category">Sub Category<font color="red" title="This field is required for registration.">*</font></label> 

                 <?php 


                 if (isset($cat_id) && !empty($cat_id)) { 



                echo $obj_category->selectBox('subcat_id', 'Select Sub Category', 'category_id', 'category_name', 

isset($ subcat_id)? $ subcat_id:'',“is_active ='1'和parent_id ='”。 $ cat_id。 “'order by category_name”,'class =“validate [required]”');

             } else { 

                  ?> 

                  <select name="subcat_id" id="subcat_id" title="Sub Category" class="validate[required]"> 

                   <option>Select Sub Category</option> 

                  </select> 

                 <?php } ?> 

                 <div class="required"> 

                  <label for="sub_sub_category">Sub Sub Category<font color="red" title="This field is required for registration.">*</font></label> 

                  <?php 


                  if (isset($subcat_id) && !empty($subcat_id)) { 

                   echo $obj_category->selectBox('subsubcat_id', 'Select Sub Sub Category', 'category_id', 'category_name', isset($subsubcat_id) ? $subsubcat_id : '', "is_active = '1' and parent_id ='" . $subcat_id . "' order by category_name", 'class="validate[required]"'); 

                  } else { 

                   ?> 

                   <select name="subsubcat_id" id="subsubcat_id" title="Sub Sub Category" class="validate[required]"> 

                    <option>Select Sub Sub Category</option> 

                   </select> 

                  <?php } ?> 

                 </div> 

               </fieldset> 
+0

您应该删除它并使用更新的代码编辑您的原始问题 – 2014-10-21 08:40:13