jquery xml

For example, if i want to get <Option></Option> Value with condition: state="AZ" and Code - "939"
in Jquery. I do not understand why below codes are not working.


<script type="text/javascript">
      function GetBondAmount(selectedCode, selectedState) {
          //alert("Value: " + selectedCode + " " + selectedState);
          //return;
          var xml = "data/bond.xml";
          var select = $('#bondAmountList');
          $(document).ready(function () {
              $.ajax({
                  type: "GET", url: xml, dataType: "xml",
                  success: function (xml) {
                      var select = $('#bondAmount');
                      //select.append('<option value="">Select Bond Type</option>');
                      $(xml).find('Bond').each(function () {
                          var name = $(this).find('Name').text();
                          var code = $(this).find('Code').text();
                          var state = $(this).find('State').text();                          
                          if ((state == selectedState) && (code == selectedCode))
                          {
                              var bondAmountType = $(this).find('BondAmountType').text();
                              if (bondAmountType == "List") {
                                  //get the list
                                  $(xml).find('BondAmount').each(function () {
                                      var option = $(this).find('Option').text();
                                      alert(option + "\n");
                                  });
                              }
                           }
                       });
                  }
              })
          });
      }
  </script>



<?xml version="1.0" encoding="utf-8" ?>
<Bonds>
  <Bond>
    <Name>Defective Title Bond</Name>
    <Code>939</Code>
    <Status>Active</Status>
    <State>AZ</State>
    <BondAmountType>Fix</BondAmountType>
    <BondAmount>
      <Option>1000</Option>
    </BondAmount>
  </Bond>
  <Bond>
    <Name>Defective Title Bond</Name>
    <Code>939</Code>
    <Status>Active</Status>
    <State>CA</State>
    <BondAmountType>List</BondAmountType>
    <BondAmount>
      <Option>100</Option>
      <Option>200</Option>
    </BondAmount>
  </Bond>  
  <Bond>
    <Name>Janitoral Business Bond</Name>
    <Code>111</Code>
    <Status>Active</Status>
    <State>CA</State>
    <BondAmountType>List</BondAmountType>
    <BondAmount>
      <Option>100</Option>
      <Option>200</Option>
    </BondAmount>
  </Bond>
</Bonds>
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.

Bob LearnedCommented:
I don't see a <data> element anywhere, but you are using "data/bond.xml".  Are you expecting JQuery to load the XML from a file or from the DOM?
ITsolutionWizardAuthor Commented:
yes
ITsolutionWizardAuthor Commented:
yes
Bob LearnedCommented:
Oops, got confused because the variable that you are using outside of the success function, is the same as the variable inside of the success function.

Does this expression return an element (I don't see an element with id='bondAmount')?

       var select = $('#bondAmount');
louisfrCommented:
Your code works fine. You don't see any message box, because those are only displayed for a "List" BondAmountType.

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
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
JavaScript

From novice to tech pro — start learning today.