if.. else if sentence

Discussion in 'Javascript' started by Obscurr, Oct 6, 2003.

  1. Obscurr

    Obscurr Guest

    hi,
    I got a problem with a standard if... else if sentence. Each one works
    alone, (ie. putting a /*..*/ around one of the conditions)but by
    combining them, only the first one triggers. The code :

    function sjekk()
    {
    if (window.document.info.organisasjon.value =='')
    {
    alert('hey!');
    return(false);
    }
    else {
    if (window.document.info.check_feste.checked == false)
    {
    var answer = confirm('Continue?');
    if (answer) {
    return (true);
    }
    else {
    return(false);
    }
    }
    }
    }

    obscurr
     
    Obscurr, Oct 6, 2003
    #1
    1. Advertising

  2. Obscurr

    Erwin Moller Guest

    Obscurr wrote:

    > hi,
    > I got a problem with a standard if... else if sentence. Each one works
    > alone, (ie. putting a /*..*/ around one of the conditions)but by
    > combining them, only the first one triggers. The code :
    >
    > function sjekk()
    > {
    > if (window.document.info.organisasjon.value =='')
    > {
    > alert('hey!');
    > return(false);
    > }
    > else {
    > if (window.document.info.check_feste.checked == false)
    > {
    > var answer = confirm('Continue?');
    > if (answer) {
    > return (true);
    > }
    > else {
    > return(false);
    > }
    > }
    > }
    > }
    >
    > obscurr




    Use alert("I am here!") in different places and see if the satement is
    reached.
    It is the very old timers approach, but always works.

    If a certain line is not reached allthough you expected it to be reached,
    you know where to start debugging.

    Hope that helps.

    Regards,
    Erwin
     
    Erwin Moller, Oct 6, 2003
    #2
    1. Advertising

  3. Obscurr

    Lee Guest

    Obscurr said:
    >
    >hi,
    >I got a problem with a standard if... else if sentence. Each one works
    >alone, (ie. putting a /*..*/ around one of the conditions)but by
    >combining them, only the first one triggers. The code :


    This doesn't address your problem directly, but it might
    help if you simplify your code:

    > if (window.document.info.check_feste.checked == false)
    > {
    > var answer = confirm('Continue?');
    > if (answer) {
    > return (true);
    > }
    > else {
    > return(false);
    > }
    > }


    can be written as:

    if (!window.document.info.check_feste.checked)
    {
    return(confirm('Continue?'));
    }
     
    Lee, Oct 6, 2003
    #3
  4. Obscurr

    W d'Anjos Guest

    In the original code if "window.document.info.organisasjon.value !=
    ''" and "window.document.info.check_feste.checked == true" nothing is
    returned.

    Try:

    function sjekk()
    {
    var answer = false;
    if (window.document.info.organisasjon.value =='')
    {
    alert('hey!');
    }
    else
    {
    if (window.document.info.check_feste.checked == false)
    {
    answer = confirm('Continue?');
    }
    }

    return answer;
    }

    (Obscurr) wrote in message news:<>...
    > hi,
    > I got a problem with a standard if... else if sentence. Each one works
    > alone, (ie. putting a /*..*/ around one of the conditions)but by
    > combining them, only the first one triggers. The code :
    >
    > function sjekk()
    > {
    > if (window.document.info.organisasjon.value =='')
    > {
    > alert('hey!');
    > return(false);
    > }
    > else {
    > if (window.document.info.check_feste.checked == false)
    > {
    > var answer = confirm('Continue?');
    > if (answer) {
    > return (true);
    > }
    > else {
    > return(false);
    > }
    > }
    > }
    > }
    >
    > obscurr
     
    W d'Anjos, Oct 6, 2003
    #4
    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. Jluis
    Replies:
    3
    Views:
    725
    Riyaz
    May 5, 2004
  2. Replies:
    25
    Views:
    702
    MonkeeSage
    Oct 1, 2006
  3. kj
    Replies:
    15
    Views:
    605
    Lawrence D'Oliveiro
    May 23, 2009
  4. A
    Replies:
    8
    Views:
    842
    James Kanze
    Aug 28, 2010
  5. Gergely Kontra
    Replies:
    16
    Views:
    254
    Devin Mullins
    Sep 20, 2005
Loading...

Share This Page