Dynamically creating Radio options
I have a array that hold sets of names and ids of data... and i want to populate it to a radio options component. Therefore, i tried to create one using java script but without success. It does create a radio options but
- they are not horizontal as i wanted.
- they each seem to be in a different group
This is my code:
code
function generateRadioFoodType(containerName)
{
var radioForm = '<fieldset id="foodTypeRadio" data-role="controlgroup" data-type="horizontal">';
for(var i=0; i < foodTypes.length; i++)
{
if(i === 0) {
Code: Select all
radioForm += '<label for="radio-choice-' + i + '">' + foodTypes[i].name + '</label> <input name="radio-choice" id="radio-choice-' + i + '" type="radio" value="' + foodTypes[i].id + '" checked="checked"/>'; } else {
radioForm += '<label for="radio-choice-' + i + '">' + foodTypes.name + '</label> <input name="radio-choice" id="radio-choice-' + i + '" type="radio" value="' + foodTypes.id + '"/>';
}
}
Code: Select all
radioForm += '</fieldset>'; var radioElement = $(radioForm);
Appery(containerName).append(radioElement);
$("#foodTypeRadio").trigger('create');
}
/code
When i try to put the result of radioForm into a HTML component as it is (not creating it from JS) then it builds correctly but like this.. doesnt work
If needed i'll post images of how it looks
Am i doing something wrong?