Advertisement
Guest User

zad2b

a guest
Oct 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <html>
  2. <head lang="pl">
  3. <meta charset="UTF-8">
  4. </head>
  5. <body>
  6.  
  7. Podaj boki prostokąta:
  8. <form>
  9.  
  10. Bok a: <input type="text" id="a" name="a"/>
  11. Bok b: <input type="text" id="b" name="b"/>
  12.  
  13.  
  14. </form>
  15. <div id="output"></div>
  16.  
  17. <script>
  18. function obliczenia(){
  19. var a=document.getElementById('a');
  20. var b=document.getElementById('b');
  21. var wynik;
  22.  
  23. if(a.value.length==0)
  24. {
  25.  
  26.  
  27. output.innerHTML=("Pole z wartością A nie może być puste");
  28. }
  29. else if (b.value.length==0)
  30. {
  31. output.innerHTML=("Pole z wartością B nie może być puste");
  32.  
  33. }
  34. else if(isNaN(a.value) || isNaN(b.value))
  35. {
  36.  
  37. output.innerHTML=("Pola muszą zawierać liczby!");
  38. }
  39. else if(0>a.value || 0>b.value)
  40. {
  41. output.innerHTML=("Wartości muszą być większe od 0!")
  42. }
  43. else
  44. {
  45.  
  46. wynik=Math.sqrt(a.value*a.value+b.value*b.value);
  47.  
  48. output.innerHTML=("Przekątna prostokąta wynosi: "+wynik);
  49. }
  50. }
  51. a.onblur=function(){
  52.  
  53. obliczenia();
  54. return false;
  55.  
  56.  
  57. }
  58. b.onblur=function(){
  59.  
  60. obliczenia();
  61. return false;
  62.  
  63.  
  64. }
  65. </script>
  66.  
  67. </body>
  68.  
  69.  
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement