Jump to content

looping not completed


suzzane2020

Recommended Posts

I have a function that reads elements from an xml file and tries to populate a select box with the elements. The problem is that if i add the line

document.myform.subcat.options[count]=newop;

[which is the one that generates the select box] the loop just executes once ,

but i have more elements.

Without the line the loop is executed succesfully.

cant figure out whats wrong. Please help?!!!

This is the code

[size=10pt]function get_xml(xmlfile)
{
var xmlDoc = xmlfile.documentElement;
var xSel1 = xmlDoc.getElementsByTagName('result');
var loop=xSel1.length;


var count=0;
for(var number=0;number<loop;number++)
{
var theText = xSel1[number].attributes.getNamedItem("name").value;
alert(theText)
var theValue = xSel1[number].attributes.getNamedItem("value").value;
//alert(theValue)
var newop= new Option(theText,theValue);

//document.myform.subcat.options.add(newop,null);
document.myform.subcat.options[count]=newop;
count++		

}

} [/size]

Link to comment
https://forums.phpfreaks.com/topic/46613-looping-not-completed/
Share on other sites

I tried this line in a simple loop and it worked fine

 

document.myform.subcat.options[count]=newop;

 

check if your loop and number variables are working through out the loop, or if there is anything else that's generating an error (you can use firefox error councel)

 

Here is the function I tried

<script>
function loadit(){
var count=0;
for(var number=0;number<5;number++)
{
var theText = "Hello World " + number;
var theValue ="Hello World " + number;
var newop= new Option(theText,theValue);

document.myform.subcat.options[count]=newop;
count++		

}

}
</script>
<form name="myform" id="myform">
<select name="subcat" id="subcat">

</select>
</form>
<button onClick="loadit()">Click</button>

Link to comment
https://forums.phpfreaks.com/topic/46613-looping-not-completed/#findComment-226982
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.