if.. else if sentence

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Obscurr

    if.. else if sentence

    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.documen t.info.organisa sjon.value =='')
    {
    alert('hey!');
    return(false);
    }
    else {
    if (window.documen t.info.check_fe ste.checked == false)
    {
    var answer = confirm('Contin ue?');
    if (answer) {
    return (true);
    }
    else {
    return(false);
    }
    }
    }
    }

    obscurr
  • Erwin Moller

    #2
    Re: if.. else if sentence

    Obscurr wrote:
    [color=blue]
    > 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.documen t.info.organisa sjon.value =='')
    > {
    > alert('hey!');
    > return(false);
    > }
    > else {
    > if (window.documen t.info.check_fe ste.checked == false)
    > {
    > var answer = confirm('Contin ue?');
    > if (answer) {
    > return (true);
    > }
    > else {
    > return(false);
    > }
    > }
    > }
    > }
    >
    > obscurr[/color]



    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

    Comment

    • Lee

      #3
      Re: if.. else if sentence

      Obscurr said:[color=blue]
      >
      >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 :[/color]

      This doesn't address your problem directly, but it might
      help if you simplify your code:
      [color=blue]
      > if (window.documen t.info.check_fe ste.checked == false)
      > {
      > var answer = confirm('Contin ue?');
      > if (answer) {
      > return (true);
      > }
      > else {
      > return(false);
      > }
      > }[/color]

      can be written as:

      if (!window.docume nt.info.check_f este.checked)
      {
      return(confirm( 'Continue?'));
      }

      Comment

      • W d'Anjos

        #4
        Re: if.. else if sentence

        In the original code if "window.documen t.info.organisa sjon.value !=
        ''" and "window.documen t.info.check_fe ste.checked == true" nothing is
        returned.

        Try:

        function sjekk()
        {
        var answer = false;
        if (window.documen t.info.organisa sjon.value =='')
        {
        alert('hey!');
        }
        else
        {
        if (window.documen t.info.check_fe ste.checked == false)
        {
        answer = confirm('Contin ue?');
        }
        }

        return answer;
        }

        obscurr@hotmail .com (Obscurr) wrote in message news:<4452c409. 0310060237.a29c 9dd@posting.goo gle.com>...[color=blue]
        > 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.documen t.info.organisa sjon.value =='')
        > {
        > alert('hey!');
        > return(false);
        > }
        > else {
        > if (window.documen t.info.check_fe ste.checked == false)
        > {
        > var answer = confirm('Contin ue?');
        > if (answer) {
        > return (true);
        > }
        > else {
        > return(false);
        > }
        > }
        > }
        > }
        >
        > obscurr[/color]

        Comment

        Working...