Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on 

xml jquery, dropdown issue

When the fnGetBondNameList is called, the selected <option> is always dropped into the last one of the dropdown list.
How can I make it just select the first option in the dropdown?


function fnGetBondNameList(bondState) {
            $.ajax({
                url: "http://localhost:5489/BondList.xml",
                success: function (xml) {
                    parseSelectXML(xml,"bondName","Bond",bondState);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert("Status: " + xhr.status);
                    alert("Error: " + thrownError);
                }
            });
    }
function parseSelectXML(xml, selectid, xmlnode, bondState) {
    var selecthtml = "", selectBondName="";
    var i = 0;
    $(xml).find(xmlnode).each(function () {
                if (bondState == $(this).find('GeneralInformation').find('State').text()) {
                    selectBondName = $(this).find('GeneralInformation').find('Name').text();
                    selecthtml += '<option value="' + selectBondName + '">' + selectBondName + "(" + bondState + ") "  + '</option>';
                    i = i + 1;
                  //  alert(selecthtml);
                }
    });
             $("#" + selectid).prop("disabled", false);
             $('#' + selectid).html(selecthtml).val(selectBondName);
             //modal information
             $('#' + "bondListFilterByState").html(selecthtml).val(selectBondName);
             $('#' + "bondlistFilterByState_selectedBondName").html(selectBondName).val;
             $('#' + "bondlistFilterByState_selectedState").html(bondState).val;
             //modal end information
         } 


<select class="select2" 
                                        id="bondState" 
                                        name="bondState" 
                                        onchange="fnSaveSingleData(this.name, '0'); fnGetBondNameList(this.options[this.selectedIndex].value);" 
                                        data-placeholder="Choose Bond State...">
                                        <option value=""></option>
                                     @foreach (var item in Model.stateList)
                                    {
                                        <option value=@item>@item</option>
                                    }
                                </select>

   <select data-placeholder="Choose Bond.." class="select2" disabled required onchange="fnSaveSingleData(this.name,'0');" id="bondName" name="bondName">
                                    <option value=""></option>
                                </select> 



<Surety>
  <SuretyLine>
    <Commercial>
      <Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Contractor 1</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>
       </GeneralInformation>
         <Image></Image>
        <Status>Online</Status>
      </Bond>
  <Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Contractor 2</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>
       </GeneralInformation>
         <Image></Image>
        <Status>Online</Status>
      </Bond>
            <Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Contractor asdfasd</Name>
          <State ID="bondState" PrefillValue="Yes">FL</State>
       </GeneralInformation>
         <Image></Image>
        <Status>Online</Status>
      </Bond>
</Commercial>
</SuretyLine>
</Surety>

Open in new window

XMLjQuery

Avatar of undefined
Last Comment
Chris Stanyon
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
XML
XML

Extensible Markup Language (XML) refers to the encoding of documents such that they can be read by both machines and humans. XML documents use tags to show the beginning and end of a set of data. XML is used extensively on websites to show volumes of data, and is the default for a number of office productivity suites. This topic includes discussions of XML-related technologies, such as XQuery (the XML Query language), XPath (the XML Path language), XSLT (eXtensible Stylesheet Language Transformations), XLink (the XML Linking language) and XPointer (the XML Pointer language).

22K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo