javascript switch(true)
        Posted  
        
            by ntan
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ntan
        
        
        
        Published on 2010-05-04T14:08:01Z
        Indexed on 
            2010/05/04
            14:18 UTC
        
        
        Read the original article
        Hit count: 206
        
JavaScript
Hi i am trying to handle an ajax json response
here is my code
success: function (j) {     
    switch(true)
    {
        case (j.choice1):
            alert("choice2");
        break;
        case (j.choice2):
                alert("choice2");
        break;
        default:
            alert("default");
        break;
    }
}
based on what j is return i do my action BUT i keep getting the default.
I have alert the j values and come correct.Some how case (j.choice1) case (j.choice2) is not working.
I tried case (j.choice1!="") (j.choice2!="") But in this scenario i keep getting the first choice.
What am i missing
© Stack Overflow or respective owner