Avatar of ITsolutionWizard
ITsolutionWizard
Flag for United States of America

asked on 

Jquery, XML, Loop in different condition

Below codes are working fine except
 
htmlOption += "<option>" + AmountMax + "</option>";

it only return 1 record/row when bondName='DMV Traffsdfasdfads', how can I loop the <Amount></Amount> and get them into the dropdown in HTML?


<Surety>
  <SuretyLine>
    <Commercial>
	<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">DMV Traffic Violators School Classroom</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>          
         </GeneralInformation>
        <Coverage Type="List">
          <Amount  PrefillValue="No" Min="10000" Max="10000" Year="1">10000</Amount>
         </Coverage>              
      </Bond>
      <Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">DMV Traffsdfasdfads</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>          
         </GeneralInformation>
        <Coverage Type="List">
          <Amount  PrefillValue="No" Min="10000" Max="20000" Year="1"></Amount>
	  <Amount  PrefillValue="No" Min="20000" Max="30000" Year="1"></Amount>
         </Coverage>              
      </Bond>
</Commercial>
  </SuretyLine>
</Surety>

function fnGetBondAmount() {
    $.ajax({
        url: "http://localhost:5489/BondList.xml",
        success: function (xml) {
            parseSelectXMLBondAmountList(xml, "bondAmount", localStorage.getItem('bondState'), localStorage.getItem('bondName'))
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("Status: " + xhr.status);
            alert("Error: " + thrownError);
        }
    });
} 
function parseSelectXMLBondAmountList(xml, selectid, bondState, bondName) {
    var html = "";
    var htmlOption = "";
    
    $('#' + selectid).prop("disabled", false);   
    $(xml).find('Bond').each(function (i, e) {
        {
            if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text())
            {
                 
                var selectedBondName = $(e).find('GeneralInformation').find('Name').text();
                var coverageType = $(e).find('Coverage').attr('Type'); 
                if (coverageType == "list") {
                    var AmountMax = $(e).find('Amount').attr('Max');
                    var AmountMin = $(e).find('Amount').attr('Min');                   
                    htmlOption += "<option>" + AmountMax + "</option>";
                }
                else {
                    var AmountMax = $(e).find('Amount').attr('Max');
                    var AmountMin = $(e).find('Amount').attr('Min');
                    $('#bondAmountPlaceHolder').append("<input type='text'  id='bondAmount' name='bondAmount' value='" + AmountMax + " />");                  
                }
            }
        }
    });   
    $("#" + selectid).html(htmlOption);
} 

<select disabled class="select2" id="bondAmount" name="bondAmount" data-placeholder=""></select>  

Open in new window

HTMLjQueryXML

Avatar of undefined
Last Comment
ITsolutionWizard

8/22/2022 - Mon