I have the following code which is loading an xml file to populate a dropdown menu. Right now the value equals the option text but I would like to have the value equal to some n
First, start by putting the numbers in your xml file. If they are related to the dropdown item, i suggest as an attribute.
example:
Acura
Aston Martin
Audi
...
then in your jquery loop:
$(xml).find('dropdown').each(function(){
$(this).find('make').each(function(){
var value = $(this).attr('value');
var label = $(this).text();
select.append("");
});
});
Note that you could probably simplify and speed up your jquery like this (untested):
$('make', xml).each(function(){
var value = $(this).attr('value');
var label = $(this).text();
select.append("");
});
UPDATE
For another, important, performance boost, do only one append() instead of as many append() as you have "make" nodes.
var optionsHtml = new Array();
$('make', xml).each(function(){
var value = $(this).attr('value');
var label = $(this).text();
optionsHtml.push( "");
});
optionsHtml = optionsHtml.join('');
select.append(optionsHtml);