0

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>
<html>
<body>

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

  <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 **/

  </script>

</body>
</html>

`
Thanks

Edited by centenond

2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by centenond
1

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.

<html>
<head>
<script type="text/javascript">
  fun calc()
  {
  var w=getElementById('weight');
  var a=getElementById('age');
  var res=getElementById('result');
  var r= w * a;
  document.form.output.value=r;
  }
  </script>
  </head>
<body>
<form>
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()>
</form>
</body>
</html>
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.