Я пытаюсь сделать сравнение в javascript, но когда я пытаюсь перенести значение поля в переменную, оно говорит мне, что оно не определено, я оставляю код ниже. Я использую текстовое поле для ввода пользователем числового значения и использую функцию нажатия кнопки, чтобы запустить функцию выделения.
//el codigo que resalta los tiempos de la fullMatriz
var tiempoCarrera = document.getElementById("tiempoC");
var comparacion = document.getElementById("comparation");
comparacion.addEventListener("click", resaltar);
//funcion para resaltar valores menores de lo indicado
function resaltar() {
for (var i = 0; i < 17; i++) {
for (var j = 0; j < 9; j++) {
if (tiempoCarrera>fullMatriz[i][j]) {
document.write(fullMatriz[i][j] + "-good-");
}
else {
document.write(fullMatriz[i][j] + "------");
}
}
document.write("</br>");
}
}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="ejecutarautomatica1.js"></script>
<p>Este es el subprogrma para marcar los tiempos menores al ingresado aquí abajo
<br/>ingrese el tiempo aqui abajo
<br/><input type="number" id="tiempoC"/>
<input type="button" value="iniciar comparación" width="300" height="50" id="comparation"/>
</p>
</body>
</html>
Стоимость неопределенная, потому что ты только манипулируешь input
но не Вашей стоимостью, чтобы получать стоимость input
debes использовать .value
в Javascript.
var tiempoCarrera = document.getElementById('tiempoC');
var comparacion = document.getElementById('comparation');
comparacion.addEventListener('click', function() {
document.getElementById('resultado').innerHTML = tiempoCarrera.value;
});
<p>Este es el subprogrma para marcar los tiempos menores al ingresado aquí abajo
<br />ingrese el tiempo aqui abajo
<br /><input type="number" id="tiempoC" />
<input type="button" value="iniciar comparación" width="300" height="50" id="comparation" />
</p>
<p id="resultado">
</p>