dongping6974 2014-08-20 10:59
浏览 51
已采纳

根据从数据库中检索的单选按钮的值触发函数

This function is intended to an Edit form, so therefore the radio buttons are initialized with the value stored in the database. Upon clicking on the radio buttons, 2 different function has to be invoked. What the function basically does is, it populates a dropdown list. E.g.: If the first radio button is selected the dropdown list must populate only the gents items.

HTML CODE

<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

<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> 

If I put $(document).ready(function() { on the top of the script, this doesn't work. So i have taken that out.

That is perfectly working when I click/focus on the dropdown. But what I want is when the page gets loaded itself with the PHP/Database value, I need the function to get started and populate the drop down. Any suggestions would be very grateful...

  • 写回答

1条回答 默认 最新

  • dongyun6003 2014-08-20 11:08
    关注

    What about something like this:

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

    Basically trigger a function onload depending on what the db value is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?