Output Element
It is used to display the result of the calculation, which can be written using the JavaScript. There are three attributes form, name and for. The form attribute is used to specify the name of the form in which the output is displayed. The name attribute is used to specify the name of the current element and the for attribute is used to specify the name of the control in which the result is displayed.
Attributes of the output element
It is used to display the result of the calculation, which can be written using the JavaScript. There are three attributes form, name and for. The form attribute is used to specify the name of the form in which the output is displayed. The name attribute is used to specify the name of the current element and the for attribute is used to specify the name of the control in which the result is displayed.
Attributes of the output element
- for- associates the output with a specific control. the value of this attribute must match the id attribute of its associated control.
- form- refers to the id of a form.
- name- specifies the name of the output element.
example 1
<!Doctype Html>
<html>
<head>
<title>output element</title>
<script type="text/javascript">
function subtract()
{
document.forms["form"]["resultsubtract"].value=123-23;
}
</script>
</head>
<body onload="subtract()">
<h1>Output element</h1>
<form name="form">
Subtracting the two numbers :
<output name="resultsubtract">
</output>
</form>
</body>
</html>
example 2
<!Doctype Html>
<html>
<head>
<title>output element</title>
<script type="text/javascript">
function subtract()
{
num1=parseInt(prompt("enter first number",0));
num2=parseInt(prompt("enter second number",0));
document.forms["form"]["resultsubtract"].value=num1-num2;
}
</script>
</head>
<body onload="subtract()">
<h1>Output element</h1>
<form name="form">
Subtracting the two numbers :
<output name="resultsubtract">
</output>
</form>
</body>
</html>
0 comments:
Post a Comment