javascript function problem #2

Discussion in 'Javascript' started by amli lola, Feb 14, 2008.

  1. amli lola

    amli lola Guest

    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...
     
    amli lola, Feb 14, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond
    Replies:
    2
    Views:
    4,525
    bruce barker
    Nov 14, 2003
  2. Replies:
    3
    Views:
    4,723
    Diez B. Roggisch
    Jun 12, 2006
  3. TJ
    Replies:
    5
    Views:
    967
    Walter Wang [MSFT]
    Jun 27, 2006
  4. Robby Bankston
    Replies:
    7
    Views:
    229
    wasntme
    Jun 17, 2005
  5. --[zainy]--
    Replies:
    1
    Views:
    288
    OmegaJunior
    Mar 31, 2007
Loading...

Share This Page