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

LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
Three things.
1. JavaScript string comparison is case sensitive. The XML element Coverage has the attribute Type with the value "List" which is uppercased, but you are comparing the value with lower cased "list" (in your line 51)
2. You are iterating Bonds, but not Amounts. You need iterate them same way, like:
                if (coverageType == "List") {
                   $(e).find('Amount').each(function (i, a) {
                    var AmountMax = $(a).attr('Max');
                    var AmountMin = $(a).attr('Min');
                    htmlOption += "<option>" + AmountMax + "</option>";
                   });
                }

Open in new window

3. Would be better to cache the function results for performance sake, don't call the same functions over and over again to obtain the same value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
It returns undefined.
0
ITsolutionWizardAuthor Commented:
It works. Expert :-D
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.