lundi 17 octobre 2016

Javascript condition not working as expected

I have a JS code which works fine when

checkQueryString != "M"

but When the value becomes checkQueryString == "M" it doesn't goes inside the loop

Here is my code.

function GridExpInfo_ClientAdd(record) {
        var checkQueryString = '<%= Request.QueryString["Mode"] %>';    
        if (checkQueryString != "M") {
            if ($('input:checked').length > 0) {

                document.getElementById("GridExpInfo_tplRowEdit3_ctl00_txtExpRefNo").disabled = true;
                document.getElementById("GridExpInfo_tplRowEdit3_ctl00_txtExpRefDt").disabled = true;

                document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').value = "";
                var last_value = 0;
                var last_text;

                var checkboxlist = document.getElementById('ddlStatus');
                var checkOptions =   checkboxlist.getElementsByTagName('input');
                var listSelected = checkboxlist.getElementsByTagName('label');

                for (i = 0; i < checkOptions.length; i++) {
                    if (checkOptions[i].checked == true) {
                        last_text = listSelected[i].innerText;
                        last_value =  checkOptions[i].value;
                        document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').innerHTML = "";
                        var ObjPriOptionExp = document.createElement("OPTION");
                        ObjPriOptionExp.text = last_text;                    
                        ObjPriOptionExp.value = last_value;
                        document.getElementById('GridExpInfo_tplRowEdit3_ctl00_ddlStageType').add(ObjPriOptionExp);
                    }
                }
            }
            if(checkQueryString == "M")
            {
               alert('Value is M now'); 
            }
            else {
                alert('Kindly select the stage');
            }
        }
    }

So my question is, why it doesn't goes inside if when it matches to M

Aucun commentaire:

Enregistrer un commentaire