-1

I am making a Java web application called Calculator. I'm using JSP, but I am not sure how to move forward.

Actually the problem is, I have designed a calculator UI and I want to display the number clicked in the text field on the same page.

How do I do this?
Please help me with an example.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Azuu
  • 836
  • 2
  • 16
  • 32

1 Answers1

1

It's a client side issue. You should use jquery:

<!DOCTYPE html>
<html>
<head>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script>
        $( function(){
            $(".numbers").click(
                function(element) {
                    var targetValue = $("#target").val();
                    $("#target").val(targetValue + element.currentTarget.value);
                }
            )
        });
    </script>
</head>
<body>
    <br />...<br />

    <input id="target" type="text" />
    <br /><input id="num1" class="numbers" type="button" value="1" />
    <br /><input id="num2" class="numbers" type="button" value="2" />
    <br /><input id="num3" class="numbers" type="button" value="3" />

    <br />...<br />
</body>
</html>
Vitalii Pro
  • 313
  • 2
  • 17