not able to call a javascript function from another javascript function

Discussion in 'JavaScript' started by priyanka19, Nov 3, 2011.

  1. #1
    Hi,
    I have written a javascript as follows:

    function abc(str){
    alert("In abc")
    var str1=false
    if(condition1){
    alert("in condition1)
    str1=true
    //code
    }
    if(condition2){
    alert("in condition2")
    str1=true
    //code
    }
    if(str1==false){
    alert("success")
    xyz(str)
    }
    }

    function xyz(str){
    //code
    }



    If condition1 or condition2 is true i am getting the respective alert messages. But am not getting the alert message for the last if even if the condition (str1==false) satisfies to be true.
    I am not able to find out the reason for this.
    Please help me out.
     
    priyanka19, Nov 3, 2011 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    It works ok when I test it. I just copy/pasted your code, and entered some simple condition1 and condition2 values, and works ok. Make sure you haven't made some mistake in code in the parts you left out from the example here, because this part works ok.
     
    pr0t0n, Nov 6, 2011 IP
  3. dixcoder

    dixcoder Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #3
    just tested your script following conditions

    function abc(str){
    alert("In abc")
    x=5;
    var str1=false
    if(x==1){
    alert("in condition1")
    str1=true;
    //code
    }
    if(x==2){
    alert("in condition2")
    str1=true
    //code
    }

    if(str1==false){
    alert("success")
    xyz(str)
    }
    }

    function xyz(str){
    alert(str);
    }

    abc('hello');

    //x==1; // went to condition 1
    //x==2; // went to condition 2

    // x==5; // went to condition false

    Script just works fine

    thanks
     
    dixcoder, Nov 7, 2011 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    this line is your error..

     alert("in condition1) 
    Code (markup):
    it should be..

     alert("in condition1") 
    Code (markup):
     
    JohnnySchultz, Nov 18, 2011 IP