validacion y resta usando onfocus y onblur en php
Publicado por jaime azair (2 intervenciones) el 03/05/2010 17:56:26
este es el codigo que conseguipero no me hace absolutamente nada, no valida y no resta(era una suma originalmente por eso la palabra sum)
<head>
<title>Prueba OnBlur y OnFocus</title>
<script>
function validarNumX(){
entero = validarInt(document.miForm.num1.value);
if(entero==""){
//document.miForm.num1.value=""
return ""
}else{
res1=true
return entero
}
}
function validarNumY(){
entero=validarInt(document.miForm.num2.value);
if(entero==""){
//document.miForm.num2.value=""
return ""
}else{
res2=true
return entero
}
}
function validarInt (valor){
valor = parseInt (valor)
if (isNaN (valor)){
return ""
}else{
return valor
}
}
function sumar(){
if(validarNumX()==""||validarNumY==""){
alert("DEBE INGRESAR DATOS CORRECTOS"
document.miForm.documenta.value = sol
}else{
sol = validarNumX()-validarNumY()
document.miForm.documenta.value = sol
}
}
</script>
</head>
<body>
<form name="miForm">
<h3>Numero 1</h3><input name="num1" OnBlur="validarNumX()" size=8><br><br>
<h3>Numero 2</h3><input maxlength="8" name="num2" OnBlur="validarNumY()" size=8><br><br>
<h3>Resultado</h3><input name="documenta" size="8" OnFocus = "sumar()"><br><br>
</form>
</body>
</html>
yno se mucho de esto es algo nuevo les agradeceria si me dijeran que tengo malo que hago para que funcione en PHP y MySQL.
gracias.
<head>
<title>Prueba OnBlur y OnFocus</title>
<script>
function validarNumX(){
entero = validarInt(document.miForm.num1.value);
if(entero==""){
//document.miForm.num1.value=""
return ""
}else{
res1=true
return entero
}
}
function validarNumY(){
entero=validarInt(document.miForm.num2.value);
if(entero==""){
//document.miForm.num2.value=""
return ""
}else{
res2=true
return entero
}
}
function validarInt (valor){
valor = parseInt (valor)
if (isNaN (valor)){
return ""
}else{
return valor
}
}
function sumar(){
if(validarNumX()==""||validarNumY==""){
alert("DEBE INGRESAR DATOS CORRECTOS"
document.miForm.documenta.value = sol
}else{
sol = validarNumX()-validarNumY()
document.miForm.documenta.value = sol
}
}
</script>
</head>
<body>
<form name="miForm">
<h3>Numero 1</h3><input name="num1" OnBlur="validarNumX()" size=8><br><br>
<h3>Numero 2</h3><input maxlength="8" name="num2" OnBlur="validarNumY()" size=8><br><br>
<h3>Resultado</h3><input name="documenta" size="8" OnFocus = "sumar()"><br><br>
</form>
</body>
</html>
yno se mucho de esto es algo nuevo les agradeceria si me dijeran que tengo malo que hago para que funcione en PHP y MySQL.
gracias.
Valora esta pregunta
0