0

Im trying to make an 'online' (HTML document) file that has an input to solve math, and I need a way to type in the numbers, and insert a 'solve me' button. I have the button, and the form by ID and class as well.

This is what I inserted into a "try it" prompt box through w3schools.com site, tried looking almost everywhere within that site to try to input it in.

<div id="A"></div>
<div id="B"></div>

<script>
    var A = 1;
    var ele = document.getElementById('A');
    var y = 2;
    var z = A + y;
    document.getElementById("demo").innerHTML = z;
</script>

Is there a way to do this? And thank you guys for your help!

3
  • So, you want a button with "solve me" text to display when you input number into an input?
    – Anakin
    May 12, 2015 at 15:52
  • Do you mean Java (as the title says) or Javascript? If Java, then you could do it all server side with a simple JSP page. Yet, this could all be done client side too with a small bit of javascript. Please clarify your question.
    – Yogi
    May 12, 2015 at 16:00
  • my bad guys, Im not the greatest at asking questions... But I respect your critique. I have the button planned, but I needed a variable var function to do inputs. May 12, 2015 at 16:13

1 Answer 1

0
<!DOCTYPE html>
<html>
<body>
<input id="A"/>
<input id="B"/>
<div id="demo"></div>
<button onclick="add();">ADD</button>
<script>
function add () {
    var A = document.getElementById('A').value *1;
    var B = document.getElementById('B').value *1;
    var z = A + B;
    document.getElementById("demo").innerHTML = z;
}
</script>

</body>
</html>

Hope this helps you, here you need to use input to have a user editable field,a div as you guessed to display your answer and button which triggers some logic.

3
  • That helped me a lot bud. May I ask that is there a setup of radio buttons I can try that solves for specific variables? May 12, 2015 at 16:09
  • are the radio buttons needed to choose different operations to perform on the input ? May 12, 2015 at 16:15
  • I have also experienced a problem @Alok I tried putting it all into a table where I have the "Please type input a" then on the right is the prompt box to type in. The problem is whenever I try to input the numbers, nothing shows, var z isnt showing. Im trying to attach the problem into the comments but i cant... The whole purpose is a clean look like a form. May 13, 2015 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.