Why doesn’t my function change value of variable?

I have a problem when I try to change value of my variable. var id … Read more Why doesn’t my function change value of variable?

I have a problem when I try to change value of my variable.

var id = null;
async function getUser() {
    let user = document.getElementById('user').value;
    let passs = document.getElementById('pass').value;

    let res = await eel.login(user, passs)();

    let text = res[0];

    let id_res = res[1];

    if (text == 'Вы успешно авторизовались!') {
        window.location.href = 'index.html';
    } else if (text == 'Неправильное имя пользователя или пароль') {
        alert(text);
    }

    var id = id_res; // that's my problematic part

    alert(id); 
}

Then, when I try to use "id" variable, it still returns "null".

async function createTask() {
    let id_res = id;

    let task = document.getElementById('need_task').value;

    let result = await eel.create_task(id_res, task);
    alert(id); // alerting null
}

In addition, in my html, I added document.getElementById(‘btn’).addEventListener(‘click’, getUser); and "document.getElementById(‘but’).addEventListener(‘click’, createTask);" to activate my functions.

As you can see, I use python eel library. So I guess, that my mistake is with that eel.
I will appreciate any of your hepl!

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *