D
D
Dima Tect2018-02-04 18:16:19
JavaScript
Dima Tect, 2018-02-04 18:16:19

Why is js variable not being written and giving NULL value?

I have a window.server_price variable, it has a value of 0 at the beginning, but then after the code it should have a certain value, but it has nothing, like this - ""
here is the code

var gameSelected = $('#game :selected').val();
    var slotsSelected = parseInt($('#slots_input').val());
    var tarifSelected = $('#tarif :selected').val();
    var dateN = parseInt($('#date :selected').val());
    var t = $('#tarif :selected').val();
    var d = parseInt($('#date :selected').val());
    if(t == 2)
    {
        if(d == - 1){
            s = parseInt($('#date input').val());
            window.server_price = 120 * s;
        } else {
            switch(d) {
                case 7:
                    window.server_price = 60;
                    break;
                case 31:
                    window.server_price = 240;
                    break;
                case 365:
                    window.server_price = 1340;
                    break;
            }
        }
    }
    else if(t == 1)
    {
        if(d == - 1){
            s = parseInt($('#date input').val());
            window.server_price = 0.27 * s;
        } else {
        switch(d) {
                case 7:
                    window.server_price = 5;
                    break;
                case 31:
                    window.server_price = 20;
                    break;
                case 365:
                    window.server_price = 240;
                    break;
            }
        }
    }
    else if(t == 0)
    {
        window.server_price = 0;
    }
    if(gameSelected == "noSelect"){
        addM('Произошла ошибка', 'Вы не указали игру для сервера');
    } else {
        if(tarifSelected == "noSelect"){
            addM('Произошла ошибка', 'Вы не указали тарифный план');
        } else {
            checkSlots();
        }
    }
    
    if(!(param1 == "ns")){
        window.wServerP = window.server_price;
        var serverPrice1 = serverPrice * param1;
        window.nServerP = serverPrice1;
        window.server_price = serverPrice1;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kulaeff, 2018-02-04
@Dima8249

Apparently none of the conditions work. Put console.log(1) in each if block and you will understand where the problem is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question