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>
<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.

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

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 ,

<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???

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.