So I have lots of radio buttons with same name but different ID and I wan't specific one of them to be selected on page load. The ID of desired button is saved to the database. I've tried this kind of solution for the actual ajax call, but alas it didn't work.
$.ajax({
type: "POST",
url: "load_config.php",
dataType: "json",
data: dataString,
success: function(data)
{
var buttonID = "#"+data.buttonID; // data.buttonID = "button5"
$(buttonID).attr("checked", true);
}
});
while the HTML part is in this sorta manner, except with a whole lot more of buttons:
<input type="radio" id="button1" name="example" value="value1"/>
<input type="radio" id="button2" name="example" value="value2"/>
<input type="radio" id="button3" name="example" value="value3"/>
<input type="radio" id="button4" name="example" value="value4"/>
<input type="radio" id="button5" name="example" value="value5"/>