基于从数据库检索到的单选按钮的值触发一个函数


Trigger a function based on the value of a radio button retrieved from the database

此函数用于Edit表单,因此使用存储在数据库中的值初始化单选按钮。在单击单选按钮时,必须调用2个不同的函数。这个函数的作用是填充一个下拉列表。。:如果选择了第一个单选按钮,则下拉列表必须只填充代理项。

<td>Catalogue Type</td>
<td>
   <input type="radio" name="catalogue_type" id="catalogue_type" class="catalogue_type" <?php if($val['gents_ladies']=="Gents"){echo "checked";} ?> value="Gents" onclick="getCategoriesGents()"/>GENTS
   <input type="radio" name="catalogue_type" id="catalogue_type" class="catalogue_type" <?php if($val['gents_ladies']=="Ladies"){echo "checked";} ?> value="Ladies" onclick="getCategoriesLadies()"/>LADIES
</td>
脚本

<script type="text/javascript">
      function getCategoriesGents(){
            var request = $.ajax({
                url: "../controller/sale.php",
                type: "POST",
                data: {action:'get_gents_categories'},  
                dataType: "html"
            });
            request.done(function(msg){ 
                $('#category_details').html(msg);
            }); 
            request.fail(function(jqXHR, textStatus) {
                alert( "Request failed: " + textStatus );
                return false;
            });
        }
        function getCategoriesLadies(){
                var request = $.ajax({
                    url: "../controller/sale.php",
                    type: "POST",
                    data: {action:'get_ladies_categories'},  
                    dataType: "html"
                });
                request.done(function(msg){
                    $('#category_details').html(msg);
                }); 
                request.fail(function(jqXHR, textStatus) {
                    alert( "Request failed: " + textStatus );
                    return false;
                });
        }
</script> 

如果我把$(document).ready(function() {放在脚本的顶部,这不起作用。所以我把它去掉了

当我点击/聚焦在下拉菜单上时,这是完美的工作。但我想要的是,当页面本身用PHP/Database值加载时,我需要这个函数来启动并填充下拉列表。

这样怎么样:

function getCategoriesGents(){
...
}
function getCategoriesLadies(){
...
}
$(document).ready(function() { 
    if(databaseVal == gents){
        getCategoriesGents()
    } else {
        getCategoriesLadies()
    }
});

根据db的值触发onload函数