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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)