+ 1
How can i link button in html form with java or java script to perform arithmetic operations
Actually i want to create a button in form. if click that button means it have to ask some input values. on providing input values it should do some arithmetic operations like addition, subtracting etc., Actually I'm creating page in adf(Application development framework). so please tell me how to do
1 Réponse
+ 13
the idea is:
you have a button which calls a js fuction when you click it:
<button onclick="add ()">Click to add </button>
in this case the button calls the function add when you press it, now we have to define the function in js
function add (){
//do something
}
next we need a input field for the user to type in the number
<input type="number" id="myNumber">
finally we have to access that number when the user clicks the button
function add (){
var number = document.getElementById("myNumber").value;
alert (number*2);
}
now the full code
<body>
<input type="number" id="myNumber">
<button onclick="add ()">Click to add </button>
<script>
function add (){
var number = document.getElementById("myNumber").value;
alert (number*2);
}
</script>
</body>
at the end I just alerted the number times 2 but you can do anything with it because it's now a variable