ITsolutionWizard
asked on
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(f unction () {
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('BondAmountTy pe').text( );
if (bondAmountType == "List") {
//get the list
$(xml).find('BondAmount'). each(funct ion () {
var option = $(this).find('Option').tex t();
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</BondA mountType>
<BondAmount>
<Option>1000</Option>
</BondAmount>
</Bond>
<Bond>
<Name>Defective Title Bond</Name>
<Code>939</Code>
<Status>Active</Status>
<State>CA</State>
<BondAmountType>List</Bond AmountType >
<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</Bond AmountType >
<BondAmount>
<Option>100</Option>
<Option>200</Option>
</BondAmount>
</Bond>
</Bonds>
in Jquery. I do not understand why below codes are not working.
<script type="text/javascript">
function GetBondAmount(selectedCode
//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(f
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('BondAmountTy
if (bondAmountType == "List") {
//get the list
$(xml).find('BondAmount').
var option = $(this).find('Option').tex
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</BondA
<BondAmount>
<Option>1000</Option>
</BondAmount>
</Bond>
<Bond>
<Name>Defective Title Bond</Name>
<Code>939</Code>
<Status>Active</Status>
<State>CA</State>
<BondAmountType>List</Bond
<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</Bond
<BondAmount>
<Option>100</Option>
<Option>200</Option>
</BondAmount>
</Bond>
</Bonds>
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?
ASKER
yes
ASKER
yes
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');
Does this expression return an element (I don't see an element with id='bondAmount')?
var select = $('#bondAmount');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.