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

Recommended Answers

All 2 Replies

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>

Thank you !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.