cowsdonthack Posted September 21, 2009 Report Share Posted September 21, 2009 So, what I need to do is I need to display all the Options <OPT> of a product <PR> whenever it's selectedHow do you load all the Options <OPT> but only for each product <PR>?JS oldTextAry = new Array();var xmlDoc;if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open("GET","data.xml",false); xmlDoc.send(""); xmlDoc=xmlDoc.responseXML; }else if (ActiveXObject("Microsoft.XMLDOM")) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("data.xml"); }var x=xmlDoc.getElementsByTagName("PR");i=0; XML <PRODUCT> <PR> <TITLE>1E Series Cylinders - 1E2 Rim Cylinder</TITLE> <IMG>http://www.asdf.com/images/cache/asdf.com-dc8ca9ef266a32a6fc42c80fbd39eb77.jpg</IMG> <ENL>http://www.asdf.com/images/cache/asdf.com-b21e748612010de9b9c722fd474419d4.jpg</ENL> <LINK> </LINK> <INFO> </INFO> <OPTION> <OPT>1</OPT> <OPT>2</OPT> <OPT>3</OPT> <OPT>4</OPT> <OPT>5</OPT> </OPTION> </PR> <PR> <TITLE>1E6 Tapered Mortise Cylinder</TITLE> <IMG>http://www.asdf.com/images/cache/asdf.com-9cb55aa0848d4c3fdd53b3600a6d8eb3.jpg</IMG> <ENL>http://www.asdf.com/images/cache/asdf.com-d92d734b54b185fa6bd551673a3d63af.jpg</ENL> <LINK> </LINK> <INFO> </INFO> <OPTION> <OPT>3</OPT> <OPT>4</OPT> <OPT>5</OPT> <OPT>8</OPT> <OPT>3</OPT> </OPTION> </PR></PRODUCT> Link to comment Share on other sites More sharing options...
boen_robot Posted September 21, 2009 Report Share Posted September 21, 2009 (edited) The easiest (though probably not the most efficient way) is to loop over each PR element, check if it's the one you're looking for (e.g. by examining the contents of the TITLE element), and if it is, grab all of it's OPT elements (again with getElementsByTagName() I think), and then do whatever you want with each. Edited September 21, 2009 by boen_robot Link to comment Share on other sites More sharing options...
cowsdonthack Posted September 21, 2009 Author Report Share Posted September 21, 2009 The easiest (though probably not the most efficient way) is to loop over each PR element, check if it's the one you're looking for (e.g. by examining the contents of the TITLE element), and if it is, grab all of it's OPT elements (again with getElementsByTagName() I think), and then do whatever you want with each.Thanks! But how do I do that? Like.. How do I getElementsByTagName() WITHIN a PR Element? Link to comment Share on other sites More sharing options...
boen_robot Posted September 21, 2009 Report Share Posted September 21, 2009 Doesn't xmlDoc.getElementsByTagName("PR")[0].getElementsByTagName("OPT"); work (i.e. return an object, and not null)? Link to comment Share on other sites More sharing options...
cowsdonthack Posted September 21, 2009 Author Report Share Posted September 21, 2009 Doesn'txmlDoc.getElementsByTagName("PR")[0].getElementsByTagName("OPT"); work (i.e. return an object, and not null)? ......oooOooooooh Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now