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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.