Forum Moderators: open

Message Too Old, No Replies

Loop Problem

only want rows to be added if arguments.length is greater than 6.

         

Conscientious Reject

4:01 pm on Feb 28, 2006 (gmt 0)

10+ Year Member



Hello,
I was wondering if someone can help me out with this. Please see comment in the function below.

function addRow()
{
var myBody = document.galleryChoice_engine.displayButton;
for (var i=myBody.options.length-1; i >= 0; i--)
{
myBody.remove(0);
}
/*
Here I only want rows to be added if arguments.length is greater than 6.
I don't know how to interate this properly.
*/
for (var i=0, myOption; i < arguments.length; i++)
{
document.images["thumb"+i].src = display[i];
myOption = document.createElement('option');
myBody.appendChild(myOption);
myOption.appendChild(document.createTextNode( arguments[i]) );
myBody.onchange = cell_click;
}
}

Thanks
Mitchell

Conscientious Reject

4:31 pm on Feb 28, 2006 (gmt 0)

10+ Year Member



AHA,

I figured it out!
Here's what I did:

function addRow()
{
var myBody = document.galleryChoice_engine.displayButton;
// Remove row[0], if present
for (var i=myBody.options.length-1; i >= 0; i--)
{
myBody.remove(0);
}
// Carry on
for (var j=0, myOption; j < arguments.length; j++)
{
document.images["thumb"+j].src = display[j]
}
/* The following is going add rows after 6.
*/
var totalDisplayed = 6;
if (arguments.length > totalDisplayed)
{
document.galleryChoice_engine.className = 'show';
}
for (var i=0, myOption; i + totalDisplayed < arguments.length; i++)
{
myOption = document.createElement('option');
myBody.appendChild(myOption);
myOption.appendChild(document.createTextNode( arguments[i]) );
myBody.onchange = cell_click;
}
}