Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>try...throw...catch</title>
- <script>
- function myFunction(){
- try{
- var x=document.getElementById('demo').value;
- if(x=="") throw "vacio";
- if(isNaN(x)) throw "no es numero";
- if(x>10) throw "es mayor";
- if(x<5) throw "es menor";
- var y=document.getElementById('mess');
- y.innerHTML="Correcto!";
- }
- catch(e){
- var y=document.getElementById('mess');
- y.innerHTML="Error: "+ e + ".";
- }
- }
- </script>
- </head>
- <body>
- <h1>Detectando errores y personalizando</h1>
- <p>Porfavor introduce un numero entre 5 y 10:</p>
- <input type="text" id="demo" />
- <input type="button" onclick="myFunction();" value="Probar valor" />
- <p id="mess"></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement