I have the following code. Trying to preset a switch based on the value of the incoming array. It will be 1-3
<input name="rating1" type="radio" value="1" /> <input name="rating1" type="radio" value="2" /> <input name="rating1" type="radio" value="3" /> $(document).ready(function() { //Setting up the radio buttons var $radios = $('input:radio[name=rating1]'); //ratingAnswer is the value I need to select in the radio group. Value=2 var ratingAnswer=answersArray[oneMap].RATING; if($radios.is(':checked') === false) { $radios.filter('[value=ratingAnswer]').attr('checked', true); }
This does not return me anything, as it searches the string ratingAnswer as the value, not the value of the ratingAnswer variable. I tried value = '+ ratingAnswer +', but I don't like this at all. How can I insert a variable into this value range. Thanks in advance.
source share