can't set a radio button with a variable that changes
I have a Dialog box were a user can make choices. With each change in choice, I fire a function to initialize several variables. Most work, but I can't set the radio button via the initialize function. What do I need to change? Edit - I also tried .prop('checked', true); with no result.
Simplified, the code is:
var countrySelected = "US"; // a global variable that changes
function initialize() {
$('input[type=radio][name=country][id=countrySelected]').attr('checked', true); //did not work
//$('#countrySelected').attr('checked', true); // did not work
alert("|" + $("input[type=radio][name=country]").val() + "|initialize"); //problem - does not change
//do other stuff - they change with the user's choice
}
The HTML for the radio buttons looks like
<label><input type="radio" id="US" name="country" value="US">United States</label>