Hi I have a select box with id 'quote-area' that I want to dynamically create options for.
It's for a mobile app using jQuery mobile and HTML5.
I have a table of areas saved locally, I'm pulling them out and putting them in a for for loop constructing a html string which I then append to the select box.
Here is my JS:
function(tx, results) {
len = results.rows.length;
var markup = [];
for(var i=0; i< len; i++){
var area_id= results.rows.item(i).area_id;
var label = results.rows.item(i).label;
markup.push("<option value='"+area_id+"'>");
markup.push(label);
markup.push("</option>");
}
alert(markup.join(""));
$('#quote-area').append(markup.join(""));
}
);
HTML:
<select name="area" id="quote-area"></select>
My alert gets run and I can see the markup has been constructed correctly. but nothing happens to my select box. I have tripple checked the selects ID.
I'm wondering if it's because the js file is loaded first then each subsequent html page is ajaxed into the DOM (jQuery mobile functionality). So when the javascipt is downloaded the select box doesn't exist yet?
Can anyone help me with this? Do I need to use some sort of live event?
UPDATE:
I've also tried using the live query plugin because I'm almost positive it because the list isn't part of the DOM when the script is loaded. But still no luck.
$('#quote-area').livequery(function(){
$(this).append($("<option></option>").attr("value",area_id).text(label));
});