how to use the .text() method with variable text to insert
I have a JSON object full of text strings. I also have a function to change the HTML text depending upon the user's selected country, which they can change around at will. Most of the function works, but the expression with .text()(function(){ }) does not change the HTML text. What do I need to change? Is the problem in the function or in the object? Here is relevant code.
var countryText = {
"eng":[
{
"US":[
{
"stateMessage2" :"2. * STATE: Type a state or US territory; click it in the dropdown",
"neighborhood3Message2":"Examples: Greenwich Village,New York; Hollywood, Los Angeles",
"monthlyRentalMessage1":"*Monthly Rental Price - $",
"rentalSquareFootageMessage":"Floor Space Area - feet²"
}
],
"GB":[
{
"stateMessage2":"2. * COUNTRY: Type a country or home nation of the United Kingdom; click it in the dropdown",
"neighborhood3Message2":"Examples: Knightsbridge,London; West End,Edinburgh; City Centre,Birmingham",
"monthlyRentalMessage1":"1. * Monthly rental price - £",
"rentalSquareFootageMessage":" Floor Space Area - meters²"
}
],
}
]
}
var changeCountry = function( countryChangeCounter, countryText ){
countrySelected = $('input[name=country]:checked').val(); //gets country abbreviation
// change user instructions to be country specific.
$('#twoSelects').hide();
$('#threeSelects').show();
initialize3Step(countryChangeCounter);
$('#stateMessage2').text( function(){
return countryText.eng.countrySelected.stateMessage2;
})
getCityFromGeonames3Step(countrySelected);
return countrySelected;
}