doumubi6784 2017-12-26 10:13
浏览 65
已采纳

如何使用jquery和php设置动态数据的默认下拉列表?

I have 2 dropdowns 1.organization 2.bank names. I have multiple organizations and mulitple banks associated with it. if i choose org ABC it will display related banks list in banks dropdown.

Example: organization ABC have total 3 banks. 1.XYZ 2.PDF 3.OPQ

so onclick ABC it will display all 3 bank names in dropdown. but it shows XYZ bank as a default value. I want to change it.I want OPQ as a default bank of organization ABC. How to achieve this in jquery. i search alot but i dont understand because i dont have much knowledge in jquery.

Below is my ajax call to get particular organization's bank list.

$org_id     = $_GET['orgId'];   
$bank_id    = $_GET['bankId'];  
if( $org_id != '')
    {           
        $bank_options = ""; 
        $get_bank_names = "select * from bank_account_details where ORG_ID = '$org_id'   
                                order by PRIORITY_SORT_ORDER";                      
        $exec_bank_names = mysql_query($get_bank_names);    
            if(!$exec_bank_names)
                {
                    die('Problem in selection'.mysql_error());
                }
            elseif( mysql_num_rows($exec_bank_names) > 0)
                {           
                    while( $row_bank_names  = mysql_fetch_array($exec_bank_names))
                        {               
                            $BANK_ACCOUNT_DETAILS_ID    =   $row_bank_names['BANK_ACCOUNT_DETAILS_ID'];
                            $BANK_NAME                  = $row_bank_names['BANK_NAME'];
                            if(($bank_id != '') && ($bank_id == $BANK_ACCOUNT_DETAILS_ID))
                                {   

                                    $bank_options .= "<option value= '$BANK_ACCOUNT_DETAILS_ID' >$BANK_NAME</option>";                              
                                }
                            else
                                {
                                    $bank_options .= "<option value= '$BANK_ACCOUNT_DETAILS_ID' >$BANK_NAME</option>";
                                }
                        }
                }
    }

echo $bank_options;

I have one of organization whose $org_id is 40 and its $bank_id is 24.

  • 写回答

1条回答 默认 最新

  • donglu4159 2017-12-26 10:21
    关注
    if(($bank_id != '') && ($bank_id == $BANK_ACCOUNT_DETAILS_ID))
                                {   
    
                                    $bank_options .= "<option value= '$BANK_ACCOUNT_DETAILS_ID' selected='selected'>$BANK_NAME</option>";                              
                                }
                            else
                                {
                                    $bank_options .= "<option value= '$BANK_ACCOUNT_DETAILS_ID' >$BANK_NAME</option>";
                                }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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