You read the value of the input as the page loads (when it has its default value, which is an empty string).
You then alert the results of that read when the function runs.
You need to read the value inside the function so that you get the value at the time the function runs.