webForumDet fria alternativet

Hur kolla om selectbox är tom?

1 svar · 140 visningar · startad av solbulle

solbulleMedlem sedan mars 20015 287 inlägg
#1

Jag har denna funktion, fungerar ända tills att document.formen.list2.options[0] inte har ett värde (som jag ser det.)

Felmeddelande: 'document.formen.list2.options.0.style' is null or not an object.

Hur löser man det? Kanske en liten If-sats på något sätt?

Det är alltså raden:
document.formen.list2.options[0].style.background='#62FF16';
som knasar.

function ladda()
{

if(mystring){

var ar=mystring.split(",");
for(var i=0; i<ar.length; i++) {
p = ar[i]-1
nummer = i+1
loadmove(document.formen.list3,document.formen.list2,laggtill,p);
}
for(var i=0; i<ar.length; i++) {
p = ar[i]-1
document.formen.list3.options[p].value = "";
document.formen.list3.options[p].text = "";
document.formen.list3.options[p].selected = 1;

document.formen.list2.options[0].style.background='#62FF16';

}
}

BumpUp(document.formen.list3);

if(mystring2){
 ladda2();
}
}
}
solbulleMedlem sedan mars 20015 287 inlägg
#2

Suck...

if (document.formen.list2.length !== 0){
document.formen.list2.options[0].style.background='#62FF16';
}

Man ser inte skogen för alla träden...

134 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
131 ms — hämta tråd, inlägg och bilagor (db)