DragonTooth™



Welcome To DragonTooth (GameDEV). Our Administrators: Emptrix, Amethyst, Shizuko~Conan, Yamino. To Contact Us, e-mail: Dragon_Tooth@live.com.
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Welcome to DragonToothDEV Forum. We are currently not taking anymore new users, however we will accept users that has Friend's Recommendation. Members who's friends are joining please pm one of the Administrators the username of your friend's newly created account to get it activated.

Share | 
 

 (Requested) Calculator Code - HTML & JavaScript

Go down 
AuthorMessage
Emptrix
Staff Administrator
avatar

Posts : 1218
Points : 1916
Reputation : 13
Join date : 2009-05-09
Age : 27
Location : The World That Never Was

PostSubject: (Requested) Calculator Code - HTML & JavaScript   Mon Nov 15, 2010 11:57 am

As requested by burma, here: Very Happy

Code:

<!Author: Emptrix>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 14 February 2006), see www.w3.org">
    <title>Welcome</title>
    <script type="text/javascript">
      function calculate() {
         var n1 = document.form1.num1_txt.value;
         var n2 = document.form1.num2_txt.value;
         
         if (isNaN(n1)) {
         alert("Number 1 must be a number.");
         document.form1.num1_txt.focus();
         document.form1.num1_txt.value = "";
         } else if (isNaN(n2)) {
         alert("Number 2 must be a number.");
         document.form1.num2_txt.focus();
         document.form1.num2_txt.value = "";
         } else if (n2 == "") {
         alert("Number 2 is required.");
         document.form1.num2_txt.focus();
         document.form1.num2_txt.value = "";
         } else if (n1 == "") {
         alert("Number 1 is required.");
         document.form1.num1_txt.focus();
         document.form1.num1_txt.value = "";
         }
         
         var result = parseInt(n1) + parseInt(n2);

         document.form1.result_txt.value=result;
      }
    </script>
  </head>
  <body>
  <form name="form1" allow="" method="post">
   <table>
   <tr>
      <td>Enter Number 1:</td>
      <td><input type="text" name="num1_txt" value="" /></td>
   </tr>
   <tr>
      <td>Enter Number 2:</td>
      <td><input type="text" name="num2_txt" value="" /></td>
   </tr>
   <tr>
      <td>Result:</td>
      <td><input type="text" name="result_txt" value="" readonly="readonly" /></td>
   </tr>
   <tr>
      <td><input type="button" name="button" value="calculate" onClick="calculate()" /></td>
   </tr>   
   </table>
  </form>
 

  <textarea rows="20" cols="150">
    <script type="text/javascript">
      function calculate() {
         var n1 = document.form1.num1_txt.value;
         var n2 = document.form1.num2_txt.value;
         
         if (isNaN(n1)) {
         alert("Number 1 must be a number.");
         document.form1.num1_txt.focus();
         document.form1.num1_txt.value = "";
         } else if (isNaN(n2)) {
         alert("Number 2 must be a number.");
         document.form1.num2_txt.focus();
         document.form1.num2_txt.value = "";
         } else if (n2 == "") {
         alert("Number 2 is required.");
         document.form1.num2_txt.focus();
         document.form1.num2_txt.value = "";
         } else if (n1 == "") {
         alert("Number 1 is required.");
         document.form1.num1_txt.focus();
         document.form1.num1_txt.value = "";
         }
         
         var result = parseInt(n1) + parseInt(n2);

         document.form1.result_txt.value=result;
      }
    </script>
  </head>
  <body>
  <form name="form1" allow="" method="post">
   <table>
   <tr>
      <td>Enter Number 1:</td>
      <td><input type="text" name="num1_txt" value="" /></td>
   </tr>
   <tr>
      <td>Enter Number 2:</td>
      <td><input type="text" name="num2_txt" value="" /></td>
   </tr>
   <tr>
      <td>Result:</td>
      <td><input type="text" name="result_txt" value="" readonly="readonly" /></td>
   </tr>
   <tr>
      <td><input type="button" name="button" value="calculate" onClick="calculate()" /></td>
   </tr>   
   </table>
  </form>
 

   </textarea>
  </body>
</html>

_________________


Last edited by Emptrix on Tue Nov 16, 2010 12:17 pm; edited 1 time in total
Back to top Go down
View user profile http://emptrix.tk
 
(Requested) Calculator Code - HTML & JavaScript
Back to top 
Page 1 of 1
 Similar topics
-
» Custom Pagination
» How to edit the banner (fixed)
» Javascript Array
» Where do you save javascript
» Quote box to HTML page

Permissions in this forum:You cannot reply to topics in this forum
DragonTooth™ :: Help & Support :: Help & Requests-
Jump to: