cancel
Showing results for 
Search instead for 
Did you mean: 

javascript problems

chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

javascript problems

anyone know why this script doesn't work?

 

    var x10 = document.forms["add-absence"]["absencetype"].value;
    var x11 = document.forms["add-absence"]["length"].value;
    if ((x10 != "Medical") && (x11 == "Partial Day")) {
        alert("Partial Day can only be used for Medial absence");
        return false;
    }    


it's currently failing even when the x10 variable is "Medical"
basically x11 variable can only be accepted when x10 variable is "Medical".

2 REPLIES 2
chenks76
All Star
Posts: 3,274
Thanks: 338
Fixes: 12
Registered: ‎24-10-2013

Re: javascript problems

ignore me!
it does work... i was passing the wrong data into variable x11 !
Anonymous
Not applicable

Re: javascript problems

Sorry @chenks76 got to spend my 10p here. But for what it is worth if the data types you are comparing are of the same type then ideally you should be using === and not == (or !== -v- !=) . Using === does not do type conversion meaning that the operation is that bit quicker when the types are the same.

For example if you have:

var A = ‘1’ ;
var B = 1 ;

If you then ask if (A === B) then the answer is No, as they are not the same type but asking if (A == B) then you’d get true due to the applied type conversion.