I am trying to change which dropdown menu is populated depending on which radio button I choose. The data for each dropdown menu is located in a different XML file. I am trying to use if-else statement to select which xml file i use, but after using alert(saddress);
I discovered that changing the radio form does not even engage the else statement. Do any of you have an idea why?
Here is my JS `$(document).ready(function(){
if($('input[name=EMVAD]:checked','#usrform').val()==$('#SenatorCheck').val()){
$.ajax({
type: "GET",
url: "senators_cfm.xml",
dataType: "xml",
success: function(xml) {
$('#StateSelect').change(function(){
$('#SenatorSelect').empty();
$('#HouseSelect').empty();
var state = $(this).val();
var select1 = $('#SenatorSelect');
var SAD = $('#SenatorAddress');
select1.append('<option value="Select a senator">Select a Senator</option>');
$(xml).find('member').each(function(){
if(state == $(this).find('state').text()){
var fname = $(this).find('first_name').text();
var lname = $(this).find('last_name').text();
select1.append("<option>"+fname+" "+lname+"</option>");
var saddress = $(this).find('address').text();
SAD.val(saddress);
}
});
});
}
});
}else if($('input[name=EMVAD]:checked','#usrform').val()==$('#HouseCheck').val()) {
$.ajax({
type: "GET",
url: "MemberData.xml",
dataType: "xml",
success: function(xml) {
$('#StateSelect').change(function(){
$('#SenatorSelect').empty();
$('#HouseSelect').empty();
select1.empty();
var state = $(this).val();
var select1 = $('#SenatorSelect');
var HAD = $('#HouseSelect');
HAD.append('<option value="Select a House Representative">Select a House Representative</option>');
$(xml).find('member-info').each(function(){
if(state == $(this).find('state postal-code').text()){
var name = $(this).find('official-name').text();
HAD.append(name);
var saddress = $(this).find('address').text();
HAD.val(saddress);
alert(saddress);
}
});
});
}
});}
}); `
Here is my html: <select id="SenatorSelect" name="senatornames" form="usrform"></select> <select id="HouseSelect" name="housenames" form="usrform"</select> <input onclick= id="StartButton" name="Start" type="button" value="Begin!" />
Lastly, here is the sample xml from the else statement code: <members> <member> <statedistrict>AK00</statedistrict> <member-info> <namelist>Young, Don</namelist> <bioguideID>Y000033</bioguideID> <lastname>Young</lastname> <firstname>Don</firstname> <middlename/> <sort-name>YOUNG,DON</sort-name> <suffix/> <courtesy>Mr.</courtesy> <prior-congress>113</prior-congress> <official-name>Don Young</official-name> <formal-name>Mr. Young of Alaska</formal-name> <party>R</party> <caucus>R</caucus> <state postal-code="AK"> <state-fullname>Alaska</state-fullname> </state> <district>At Large</district> <townname>Fort Yukon</townname> <office-building>RHOB</office-building> <office-room>2314</office-room> <office-zip>20515</office-zip> <office-zip-suffix>0200</office-zip-suffix> <phone>(202) 225-5765</phone> <elected-date date="20141104">November 4, 2014</elected-date> <sworn-date date="20150112">January 12, 2015</sworn-date> </member-info> <committee-assignments> <committee comcode="II00" rank="2"/> <committee comcode="PW00" rank="2"/> <subcommittee subcomcode="II10" rank="2"/> <subcommittee subcomcode="II13" rank="2"/> <subcommittee subcomcode="II24" rank="1" leadership="Chairman"/> <subcommittee subcomcode="PW05" rank="2"/> <subcommittee subcomcode="PW07" rank="2"/> <subcommittee subcomcode="PW12" rank="2"/> </committee-assignments>
Aucun commentaire:
Enregistrer un commentaire