udayakumarb udayakumarb - 1 year ago 47
Javascript Question

Jquery Not working in onchange function (Play scala view page and Ajax)

I have the following Jquery code on play Scala view page with script tag But if and else if statement not working already I search it, But my condition is different (I have session value is "ADC")

$('#sampleId').on('change', function(){

var x = document.getElementById("sampleId").value;
var y = document.getElementById("cId").value;



$.map(result,function(obj, i){

var status = obj.values

if('@role' == "ADC" && '+ status +' == "Applied" || "Verified"){


} else if('@role' == "ADC" && '+ status +' == "Approved" || "Admitted"){





If i will any changes in my code?

Answer Source

Your if conditions look completely mangled. This for instance...

if('@role' == "ADC" && '+ status +' == "Applied" || "Verified")

...looks nonsensical. This statement will be true every time because of that last OR condition. It looks like you are doing that most classic of beginner mistakes when you want to check if a variable is one value or another.

The wrong way to do it.

if (myVariable == 'foo' || 'bar')

The right way to do it.

if (myVariable == 'foo' || myVariable == 'bar')

Also I cannot figure out what you are trying to do. This, for instance,...

'@role' == "ADC"

...seems to query if the literal string @role is equal to the literal string ADC.

My answer to you is to completely revise your if statements because 1) they are unreadable and 2) they are wrong, for reasons mentioned above.

My best guess is that your if-statement should look something like this (assuming that @role is some Scala specific substitution:

if("@role" == "ADC" && (status == "Applied" || status == "Verified")) {
} else if("@role" == "ADC" && (status == "Approved" || status == "Admitted")) {