Computer >> Computer tutorials >  >> Programming >> HTML

How to include the result of a calculation in HTML5?


Use the <output> tag in HTML5 to specify the result of a calculation. The HTML <output> tag also supports the following additional attributes −

Attribute
Value
Description
for How to include the result of a calculation in HTML5?
for
List of IDs of other elements, i.e. it indicates the elements who have contributed input value to the calculation.
form How to include the result of a calculation in HTML5?
form
Enables to place output elements anywhere within a document.
name How to include the result of a calculation in HTML5?
name
It is the name of the element.

Example

You can try to run the following code to learn how to implement <output> tag in HTML5 −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Output Tag</title>
   </head>
   <body>
      <form oninput = "sumresult.value = parseInt(z1.value)+parseInt(z2.value)+parseInt(z3.value)">
         <input type = "range" name = "z1" value = "0" /> +
         <input type = "number" name = "z2" value = "30" /> +
         <input type = "number" name = "z3" value = "60" /><br />
         The output is: <output name = "sumresult"></output>
      </form>
   </body>
</html>