0

有问题的下拉列表称为 subCategory ,它的内容是通过选择另一个下拉类别来填充的,该类别的 onchange 事件正在触发 ajax 请求。

问题是,即使子类别的内容按预期填充(可见)并且我可以看到它们并在子类别下拉列表中选择它们,但当我执行 php 帖子时,<option value="subCategory1">Select a subcategory</option>无论我是否都只能获取初始选项的值选择任何其他元素。

也许dom没有刷新,但我不确定..

$_REQUEST提交后直接的PHP print_r

Array ( [act] => additem  [category] => 200381 [subCategory] => subCategory )

HTML(已编辑)

<form id="additemform" action="add-item.php?act=additem" method="post" enctype='multipart/form-data'>
    <div id="section-category">
        <select id="category" class="category"  name="category">
            <option value="category1">Select a category</option>
            {html_options values=$cat_id_array  options=$cat_names_array selected=$smarty.session.additem_category} 
        </select>
        <p class="test" id="boxCity">
        <select id="subCategory"  class="subCategory" name="subCategory">
            <option value="subCategory1">Select a subcategory</option>
                {html_options  options=$smarty.session.subcategories selected=$smarty.session.additem_subcategory}
        </select>
        </p>
    </div>
    <!--/#section-category-->
    <div class="bottom-area">
        <input id="submit-addItem" type="button" value="Add my item" />
    </div>                    
</form>

页面来源:

<div id="section-category">
 <select id="category" class="category"  name="category">
    <option value="category1">Select a category</option>
    <option value="200381" selected="selected">Antiques</option>
    <option value="200841" >Other cat</option>
</select>
<p class="test" id="boxCity">
<select id="subCategory"  class="subCategory" name="subCategory">
    <option value="subCategory1">Select a subcategory</option>
    <option value="23430118">Digital Art</option>
    <option value="6643435">Photographic Images</option>
</select>
</p>
</div><!--/#section-category-->

查询

$(function () {
    //$("#subCategory").selectbox();
    $("#section-category #category").selectbox({
    onChange: function () {
        var id=$(this).val(); 
        var dataString = 'id='+ id;  

        $.ajax  
        ({  
        type: "POST",  
        url: "findsub.php",  
        data: dataString,  
        cache: false,  
        success: function(html)  
        {  
            //$("#subCategory").selectbox("detach")
            $("#subCategory").html(html);
        // $("#section-category #subCategory").selectbox();
        }  
    }); 


},
effect: "slide"
}); 

$('.subCategory').change(function() {
//NOTE I CAN SEE THE SELECTED VALUE OF THE SUBCATEGORY NORMALLY IN THIS ALERT   
    alert($(this).serialize());
return false;
});
4

1 回答 1

0

这不起作用的原因是我有另一个选择框(更下方),其名称和第一个选项与子类别相同,PHP 正在采用这个值。

这现在有效,谢谢

于 2013-01-20T15:29:00.007 回答