samedi 25 février 2017

If/ Else in Javascript doesn't work [on hold]

I wanted to make a javascript if else. I don't know why, but it always takes the if value = 2. Because of the alert, I can see, that the value is the right one. So no matter what value the variable value has, it always does the value = 2 thing.

    function luftfeuchtigkeit(value) {
    alert(value);
    if (value = 0) {
        $.ajax({
            type: 'GET',
            url: 'cgi-bin/luftfeuchtigkeit0.py'
        }).done(function (data) {

            window.open("luftfeuchtigkeit0.html", "_self");
        });
    } else {
        if (value = 1) {
            $.ajax({
                type: 'GET',
                url: 'cgi-bin/luftfeuchtigkeit1.py'
            }).done(function (data) {

                window.open("luftfeuchtigkeit1.html", "_self");
            });
        } else {
            if (value = 2) {
                $.ajax({
                    type: 'GET',
                    url: 'cgi-bin/luftfeuchtigkeit2.py'
                }).done(function (data) {

                    window.open("luftfeuchtigkeit2.html", "_self");
                });
            } else {
                $.ajax({
                    type: 'GET',
                    url: 'cgi-bin/luftfeuchtigkeit3.py'
                }).done(function (data) {

                    window.open("luftfeuchtigkeit3.html", "_self");
                });
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire