0

plz chk my coding n tell me whr I am wrong.

<html>
  <head>
   <title>
    My simple calculator
   </title>
  </head>
     <script language="JavaScript">
     <!--
     function addit()
      {
 
          var num1=document.calform.one.value;
          var num2=document.calform.two.value;
           document.calform.result.value=parseFloat(num1)+parseFloat(num2);
          
       }
     <!--
         function minus()
      {
           var num1=document.calform.one.value;
           var num2=document.calform.two.value;
             document.calform.result.value=parseFloat(num1)-parseFloat(num2);
       
       }

     -->
       </script>
       <body>Add subtract Calculator
         <form name="calform">
           <p>
              First Number:<input type="text" name="one" maxlength="3">
           <p>
              Second Name:<input type="text" name="two" maxlength="3">
           <p>
              Result:<input type="text" name="result" maxlength="9" disabled>
           <p>
                <input type="button"name="add"value="Add Them!"onclick="addit()">
                <input type="button"name="minus"value="Subtract Them!"onclick="minus()">
                <input type="reset" value="Reset!">
         </form>
      </body>
</html>

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

4
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by Alxandr
0
<html>
  <head>
   <title>
    My simple calculator
   </title>
  </head>
     <script language="JavaScript">
     <!--
function addit = function()
      {
 
          var num1=document.getElementById('one').value;
          var num2=document.getElementById('two').value;
           document.getElementById('result').value=parseFloat(num1)+parseFloat(num2);
          
       }
         function minusit()
      {
 
          var num1=document.getElementById('one').value;
          var num2=document.getElementById('two').value;
           document.getElementById('result').value=parseFloat(num1)-parseFloat(num2);
          
       }
     -->
       </script>
       <body>Add subtract Calculator
         <form name="calform">
           <p>
              First Number:<input type="text" name="one" id="one" maxlength="3" />
           <p>
              Second Name:<input type="text" name="two" id="two" maxlength="3" />
           <p>
              Result:<input type="text" name="result" maxlength="9" id="result" disabled="disabled" />
           <p>
                <input type="button"name="add"value="Add Them!"onclick="addit();" />
                <input type="button"name="minus"value="Subtract Them!"onclick="minusit();" />
                <input type="reset" value="Reset!" />
         </form>
      </body>
</html>

Try that, worked for me. And try writing at least a bit better English.

0

please check the syntax.. it is onClick not onclick.Thats why it is not working

I checked it again with onClick , but still only add them button is working. subtract them button still not working , what should I do now ,

0
<html>
  <head>
   <title>
    My simple calculator
   </title>
  </head>
     <script language="JavaScript">
     <!--
function addit = function()
      {
 
          var num1=document.getElementById('one').value;
          var num2=document.getElementById('two').value;
           document.getElementById('result').value=parseFloat(num1)+parseFloat(num2);
          
       }
         function minusit()
      {
 
          var num1=document.getElementById('one').value;
          var num2=document.getElementById('two').value;
           document.getElementById('result').value=parseFloat(num1)-parseFloat(num2);
          
       }
     -->
       </script>
       <body>Add subtract Calculator
         <form name="calform">
           <p>
              First Number:<input type="text" name="one" id="one" maxlength="3" />
           <p>
              Second Name:<input type="text" name="two" id="two" maxlength="3" />
           <p>
              Result:<input type="text" name="result" maxlength="9" id="result" disabled="disabled" />
           <p>
                <input type="button"name="add"value="Add Them!"onclick="addit();" />
                <input type="button"name="minus"value="Subtract Them!"onclick="minusit();" />
                <input type="reset" value="Reset!" />
         </form>
      </body>
</html>

Try that, worked for me. And try writing at least a bit better English.

I used it too. still not working properly , dear I have IE , Is this fault in my browser???

0

when i first loaded this code into firefox it gave an error, then i changed this line:

#
function addit = function()

to this:

#
function addit ()

and it works in both FF 3.5 and IE 8

0

please check the syntax.. it is onClick not onclick.Thats why it is not working

Sorry to say so, but this is wrong. Old plain HTML 4.01 allowed you to case attributes as you wanted if I'm not totally mistaken, but XHTML states that all attributes MUST be lowercase. It's onclick.

0

when i first loaded this code into firefox it gave an error, then i changed this line:

#
function addit = function()

to this:

#
function addit ()

and it works in both FF 3.5 and IE 8

Sorry, my bad, something must have gone wrong copy pasting. :-S

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.