Hey guys i have a question, so i need boxess in my website to store name, weight, etc
now i know this is done with html

but i need to be able to control and do math with those number
how i would do thaht with java ? i mean i know how to do it with java but...
what am trying to say is how i manipulate the entry of the html box with java

 `<!DOCTYPE html>

<form action="">
Weigth: <input type="text" name="weigth"><br>
Age: <input type="text" name="age ">

  <script type="text/javascript">

  /** What i do here if i want to lets say multiply age and weigth and put the result in another box **/




Edited by centenond

4 Years
Discussion Span
Last Post by centenond

Use a function to calculate the result in javascript.
Id of the form elements are more important than its name. So, always set an id to all the form elements. Using the id, you can get the value or property of the text box or div or whatever.

<script type="text/javascript">
  fun calc()
  var w=getElementById('weight');
  var a=getElementById('age');
  var res=getElementById('result');
  var r= w * a;
Weight: <input type="text" id="weight"><br>
Age: <input type="text" id="age"><br>
Result:<input type="text" name="output" id="result"><br>
<input type="button" onclick=calc()>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.