javascript function problem #2

A

amli lola

Thanks Lasse for your post, worked (with a little fix) perfect.

Now, I have a similar problem (again function needed) with this code



function selected(sjedalo)
{
if((sjedalo=="A01")&&(sjedala_selektirana[1]==0)&&(brojac<5))
{
if(sjedala_slobodna[1])
{
sjedala_selektirana[1]=1;
brojac++; // counter++
if (document.form2.s1.value == "")
document.form2.s1.value = "A01";
else if (document.form2.s2.value == "")
document.form2.s2.value = "A01";
else if (document.form2.s3.value == "")
document.form2.s3.value = "A01";
else if (document.form2.s4.value == "")
document.form2.s4.value = "A01";
else if (document.form2.s5.value == "")
document.form2.s5.value = "A01";



}
}



else if((sjedalo=="A01")&&(sjedala_selektirana[1]==1)&&(brojac>0))
{
if(sjedala_slobodna[1])
{
sjedala_selektirana[1]=0;
brojac--;
if (document.form2.s1.value == "A01")
document.form2.s1.value = "";
else if (document.form2.s2.value == "A01")
document.form2.s2.value = "";
else if (document.form2.s3.value == "A01")
document.form2.s3.value = "";
else if (document.form2.s4.value == "A01")
document.form2.s4.value = "";
else if (document.form2.s5.value == "A01")
document.form2.s5.value = "";
}
}



else if((sjedalo=="A02")&&(sjedala_selektirana[2]==0)&&(brojac<5))
{
if(sjedala_slobodna[2])
{
sjedala_selektirana[2]=1;
brojac++;
if (document.form2.s1.value == "")
document.form2.s1.value = "A02";
else if (document.form2.s2.value == "")
document.form2.s2.value = "A02";
else if (document.form2.s3.value == "")
document.form2.s3.value = "A02";
else if (document.form2.s4.value == "")
document.form2.s4.value = "A02";
else if (document.form2.s5.value == "")
document.form2.s5.value = "A02";
}
}



else if((sjedalo=="A02")&&(sjedala_selektirana[2]==1)&&(brojac>0))
{
if(sjedala_slobodna[2])
{
sjedala_selektirana[2]=0;
brojac--;
if (document.form2.s1.value == "A02")
document.form2.s1.value = "";
else if (document.form2.s2.value == "A02")
document.form2.s2.value = "";
else if (document.form2.s3.value == "A02")
document.form2.s3.value = "";
else if (document.form2.s4.value == "A02")
document.form2.s4.value = "";
else if (document.form2.s5.value == "A02")
document.form2.s5.value = "";
}
}

// it goes on until sjedalo=="A016"

// notice that each sjedalo has two 'else if's', one for
sjedala_selektirana=0 && brojac<5 and one for sjedala_selektirana=1 &&
brojac>0

and the only difference is here

// for first if
sjedala_selektirana[2]=1;
brojac++; // counter++

// for second if
sjedala_selektirana[2]=0;
brojac--; // counter--


Thank you again...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top