C# Jadu
  • Home
  • Asp.net
  • Web Design
    • Html
    • Css
    • Java Script
  • Bootstrap
  • Sql
    • Queries
    • Stored Procedures
  • About Me
    • About Myself
    • My Projects
    • My CV
  • Gallery
  • Do you Know?

Sunday, 4 October 2015

How to create a simple calculator using html and java script ?

 Deepak Chaudhary     11:29     Js     No comments   

Hi Friends...


In this article we learn how to make a calculator using html and java script
C# jadu

In this calculator user will choose operation which he or she wants to perform then click choose then he or she will have to fill two numbers for operation then click submit for result.


Step 1: Html Code


<html>

<head>

</head>

<script type="text/javascript">
    function deepak() {
        if (document.getElementById('a').checked == true) {
            document.getElementById('bb').value = 'Add';
        }
        else if (document.getElementById('b').checked == true) {
            document.getElementById('bb').value = 'Sub';
        }
        else if (document.getElementById('c').checked == true) {
            document.getElementById('bb').value = 'Mul';
        }
        else if (document.getElementById('d').checked == true) {
            document.getElementById('bb').value = 'Div';
        }
        else {
            alert("select any option");
        }
    }
    function amit() {
        if (document.getElementById('i1').value == "" || document.getElementById('i2').value == "") {
            alert("enter the value");
        }
        else {
            var aaa = document.getElementById('bb').value;
            if (aaa == "") {
                document.getElementById('cc').value == "enter two number";
            }
            else {
                if (aaa == "Add") {
                    var abc1 = document.getElementById('i1').value;
                    var abc2 = document.getElementById('i2').value;
                    var result = Number(abc1) + Number(abc2);
                    document.getElementById('cc').value = result;
                }
                else if (aaa == "Sub") {
                    var abc1 = document.getElementById('i1').value;
                    var abc2 = document.getElementById('i2').value;
                    var result = Number(abc1) - Number(abc2);
                    document.getElementById('cc').value = result;
                }
                else if (aaa == "Mul") {
                    var abc1 = document.getElementById('i1').value;
                    var abc2 = document.getElementById('i2').value;
                    var result = Number(abc1) * Number(abc2);
                    document.getElementById('cc').value = result;
                }
                else if (aaa == "Div") {
                    var abc1 = document.getElementById('i1').value;
                    var abc2 = document.getElementById('i2').value;
                    var result = Number(abc1) / Number(abc2);
                    document.getElementById('cc').value = result;
                }
            }
        }
    }

</script>
<body>
    
    <div style="margin-left:550px; margin-top:50px;padding:10px; border:2px groove #ff6a00; width:180px;">
    <table>

        <tr>
            <td>Choose an option 
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" disabled id="bb">
            </td>
        </tr>
        <tr>
            <td>
                <input type="radio" name="a" id="a">Add<br>
                <input type="radio" name="a" id="b">Sub<br>
                <input type="radio" name="a" id="c">Mul<br>
                <input type="radio" name="a" id="d">Div<br>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="choose" onclick="deepak()"><br>
            </td>
        </tr>
        <tr>
            <td><input type="text" id="i1" placeholder="Enter number first"><br>
             <input type="text" id="i2"  placeholder="Enter number second"><br>
             <input type="text" disabled id="cc" placeholder="Result"><br>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="submit" onclick="amit()"><br>
            </td>
        </tr>
    </table>
        </div>
</body>
</html>

Your design will look like this 




Demo : 






  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Most Popular posts

  • How To Create Image wipe Effect With CSS3 Webkit Animation
    Hi Friends... In this article we learn how to create a Image wipe effect with CSS3. CSS transition and animations provide a way for web de...
  • CSS 3D Cube
    Hi Friends... CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a lang...
  • CSS 3D Transforms
    Hi Friends... There is nothing more flashy and full with eye-candy than an impressive 3D CSS demo. Although its utility outside of demos ...

About Me

Deepak Chaudhary
View my complete profile

Copyright © C# Jadu | Powered by Blogger
Design by Deepak Chaudhary