Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML & CSS How do i make a math form?

joshii1

Active Coder
Hello y'all! im currently trying to make a form with two inputs where you would enter in a certain number in each box then press submit then once submitted it would divide those two numbers together, for example Box #1: 100 Box #2: 50 Submit? then once submitted, it would divide those two boxes by each other. and display the answer. can you guys help me out? i dont know where to start or what to do to make it work. thanks! <3
 
Solution
You can start from here -
HTML:
<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Devide</title>
    
    <style>
        main {
            width: 100%;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        main p {
            margin: 10px;
        }
        #submit {
            margin: 10px;
            padding: 5px 10px;
            border: none;
            background-color: #47FF00;
        }
        #submit:hover {
            cursor: pointer;
            background-color: #339C0A...
You can start from here -
HTML:
<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Devide</title>
    
    <style>
        main {
            width: 100%;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        main p {
            margin: 10px;
        }
        #submit {
            margin: 10px;
            padding: 5px 10px;
            border: none;
            background-color: #47FF00;
        }
        #submit:hover {
            cursor: pointer;
            background-color: #339C0A;
        }
    </style>
</head>

<body>
    <main>
        <p>Enter Number #1: </p><input type="text" id="b1" />
        <p>Enter Number #2: </p><input type="text" id="b2" />
        <input type="submit" id="submit" value="Submit" onclick="myFunction()" />
    </main>
    
    <script>
        function myFunction() {
            var b1 = document.getElementById("b1").value;
            var b2 = document.getElementById("b2").value;
            
            var result = b1 / b2;
            alert("Result: " + result);
        }
    </script>

</body>

</html>
 
Solution
Change this -
JavaScript:
<script>
     function myFunction() {
         var b1 = document.getElementById("b1").value.replace(/,/g, '');
         var b2 = document.getElementById("b2").value;
            
         var result = b1 / b2;
         alert("Result: " + result);
         console.log(b1);
     }
</script>
 
Last edited:

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom