How can Change the value of my input dynamically in Javascript

I’m building a simple Random Number Generator app, where I have a max value and min value as inputs, I’ve passed the values initially using HTML, but when I have my form displayed and I want to change the inputs values to other values to have another result, the initial values persist

What do you think guys?

My script file

let maxNum = parseFloat(document.getElementById("max").value);
let minNum = parseFloat(document.getElementById("min").value);
const result = document.getElementById("result");
const submitButton = document.getElementById("button");
const form = document.getElementById("form");


minNum = Math.ceil(minNum);
maxNum = Math.floor(maxNum);

//Onsubmit 
 function GetNumberSubmit(e) {
     e.preventDefault();
    if(!maxNum || !minNum) {
        alert("Please enter Both value");
    }

     else if(maxNum && minNum ) {
        console.log(GetRandomNumber())
        result.value = GetRandomNumber();
    }
    else {
        return "";
    }
    
}

function GetRandomNumber() {
    const randomNumber = Math.floor(Math.random() * (maxNum - minNum +1 ) + minNum );
    return randomNumber;
}


form.addEventListener('submit', GetNumberSubmit);

html

<div class="game-container">
    <h1>Random number Generator</h1>
    <form id="form">
       <input type="text" 
              placeholder="" 
              id="result" value=""/>
        <div class="form-control-container">
            <div class="form-control">
                <label for="max">Max</label> 
                <input id="max" value="10"/>
            </div>

            <div class="form-control">
                <label for="max">Min</label> 
                <input id="min" value="5"/>
            </div>
        </div>
        <button  class="submit-btn" id="button">Hit it</button>
    </form>
</div>

Answer

You should work on your script part. The variables minNum and maxNum are only once requested. You should redefine them inside your function

function GetNumberSubmit(e) {
    let maxNum = parseFloat(document.getElementById("max").value);
    let minNum = parseFloat(document.getElementById("min").value);
    minNum = Math.ceil(minNum);
    maxNum = Math.floor(maxNum);
    //...
}

And your GetRandomNumber function should take maxNum and minNum as arguments.

function GetRandomNumber(maxNum, minNum) {...}