making online calculator using HTML and javascript Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of making online calculator using HTML and javascript without wasting too much if your time.

The question is published on by Tutorial Guruji team.

i want to make online calculator, i figured out, that i can use forms from HTML, i made some forms, but there is little problem, i need to take values from (input type=”number” name=”first number”) and (input type=”number” name=”second number”) and put them into script equation and then result write in (input type=”text”) when user file numbers and press submit button http://jsfiddle.net/nco5r74k/

<pre>
<!DOCTYPE html> 
<html lang="cs-CZ"> 
    <head>
        <meta charset="UTF-8">
        <meta name="generator" content="Prace"> 
        <title>kalkulačka</title> 
    </head> 
    <body>        
        <form>
        <label for="vypln_cislo1">zadej zde první číslo</label> <input type="number" name="prvni_cislo" min="0" max="10000">
        <select name="znamenko">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="x">x</option>
        <option value=":">:</option>
        </select>
        <label for="vypln_cislo2">zadej zde druhé číslo</label> <input type="number" name="druhe" min="0" max="10000">
        <input type="submit" value="vypočítat">
        <label for="vysledek">výsledek:</label> <input type="text" size="15" name="vysledek" readonly>
        </form>
        <script>
            var a, text;
            y =
            x = 
            a = y + x
            text = + a;
            document.write(text);
        </script>
        <script>
            var b, text;
            y =
            x = 
            b = y - x
            text = + b;
            document.write(text);
        </script>
        <script>
            var c, text;
            y =
            x = 
            c = y * x
            text = + c;
            document.write(text);
        </script>
        <script>
            var d, text;
            y = 
            x = 
            d = y / x
            text = + d;
            document.write(text);
        </script>
    </body> 
</html>
</pre>

Answer

Here’s a little example of how you can use document.getElementById() to read from input elements and write to a span element, using the onclick event handler from a button.

A: <input id="a" value="3"/><br/>
B: <input id="b" value="5"/><br/>
<button onclick="document.getElementById('product').innerText = document.getElementById('a').value * document.getElementById('b').value;">Calculate</button>
<br/>
A * B = <span id="product"></span>
We are here to answer your question about making online calculator using HTML and javascript - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji