i looked @ few threads, code have unable make work. jquery creates html dropdown using information xml file. need remove duplicate options drop down. not necessary need figure out how show items in category chosen drop down.
so right displaying every category many times appears in xml. goal have display each category once. tip on how show items contain category appreciated.
jquery:
$(document).ready(function () { $.ajax({ type: "get", url: "xml/store.xml", datatype: "xml", success: function (xml) { $(xml).find("info").each(function () { var option = $(this).find('category').text(); $('#dropdown').append('<option>' + option + '</option>'); }); } }); });
html:
<form> <select id="dropdown"> <option></option> </select> </form>
xml sample:
<products> <info> <image> <src>images/bosubalancetrainer.jpg</src> </image> <name>bosu sport balance trainer</name> <brand>bosu</brand> <price>$85.95</price> <category>bosu ball</category> </info> <info> <image> <src>images/bosupro.jpg</src> </image> <name>bosu pro balance trainer</name> <brand>bosu</brand> <price>$149.95</price> <category>bosu ball</category> </info> <info> <image> <src>images/bowflexdumbbell.jpg</src> </image> <name>552 adjustable dumbbells</name> <brand>bowflex</brand> <price>$349.00</price> <category>weights</category> </info> <info> <image> <src>images/bowflexbench.jpg</src> </image> <name>5.1 series bench</name> <brand>bowflex</brand> <price>$259.00</price> <category>equipment</category> </info> </products>
add check condition..
success: function (xml) { var arr = new array(); $(xml).find("info").each(function () { var option = $(this).find('category').text(); if($.inarray(option, arr) > -1) { // nothing } else { $('#dropdown').append('<option>' + option + '</option>'); // push array arr.push(option); } }); }
Comments
Post a Comment