Estaba haciendo una función javascript en la que necesito confirmar la entrada. Escribí el siguiente código pero da un valor negativo, es decir, la parte "else" incluso si ingreso un valor válido. ¿Alguien puede sugerir una solución? archivoPasando valores html a las funciones javascript
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript App</title>
<script type="text/javascript" src="app1.js">
</script>
</head>
<body><h1 id="heading1" style="text-align:center; height:auto; width:auto; font-family:'Arial Black', Gadget, sans-serif">Determinant of a nxn matrix</h1>
<p id="paragraph1" style="font-family:'Arial Black', Gadget, sans-serif"> This program allows you to compute the determinant of a nxn matrix</p>
<p>
Input the order of the matrix
<br />
<input type="text" maxlength="3" name="value" />
<input type="button" value="submit" onclick="verifyorder(value)" />
</p>
<p id="error"></p>
<p id="detspace"></p>
</body>
</html>
Javascript archivo:
function verifyorder(order){
;
if(order>0){
return true;
}
else{
alert("Sorry, you need to enter a positive integer value, try again");
document.getElementById('error').innerHTML="Sorry, you need to enter a positive integer value, try again";
}
}
El código que envió claramente corre * * después de los problemas que se producen. Supongo que has pasado una * cadena *, no un número, pero sin el código que invoca 'verifyorder' no puedo decirlo. – Malvolio
No hay nada en su código que asocie la variable de Javascript (indefinida y no inicializada) denominada "valor" con un elemento DOM que tiene el nombre de "valor". Necesita de alguna manera decirle al Javascript que encuentre ese elemento de entrada y que extraiga su valor. –
¿Cómo hago eso? –