Показать сообщение отдельно
  #1 (permalink)  
Старый 03.05.2021, 23:32
Новичок на форуме
Отправить личное сообщение для davno_pora Посмотреть профиль Найти все сообщения от davno_pora
 
Регистрация: 03.05.2021
Сообщений: 2

getElementById не рабоает - всегда идет NaN
HTML
<label>Width in mm:</label><br>
<input type="number" min=0 class="spacerSize" id="width" /><br/>
<label>Height in mm:</label><br>
<input type="number" min=0 class="spacerSize" id="height" /><br/>
<button class="btn btn-hero" onclick="showResults()">click me</button>

JS
var width =  document.getElementById("width").value;
var height = document.getElementById("height").value;

function showResults() {
	console.log(width);
    width = parseInt(width);
    height = parseInt(height);
	console.log(width);
	console.log(height);
}

когда нажыимаю кнопку, получается NaN. Почему?
Ответить с цитированием