Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > javascript function problem #2

Reply
Thread Tools

javascript function problem #2

 
 
amli lola
Guest
Posts: n/a
 
      02-14-2008
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[i]=0 && brojac<5 and one for sjedala_selektirana[i]=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...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
assigning session a javascript value in javascript function --[zainy]-- Javascript 1 03-31-2007 05:11 PM
Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function ycoci0@gmail.com Python 3 06-12-2006 07:45 AM
** Dynamically writing html/javascript from a javascript function ** Robby Bankston Javascript 7 06-17-2005 08:23 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Javascript function works but C# function doesn't execute Jim Hammond ASP .Net 2 11-14-2003 08:43 PM



Advertisments