Example10: Write a javascript program to accept an integer and display it.
Design
Program: [Link]
<!DOCTYPE html>
<html>
<head>
<title> Displaying an integer </title>
</head>
<body>
<label> Enter one integer</label>
<input type="text" id="textbox1"><br><br>
<input type="submit" value="Display" onclick="show()">
<p id="display" style="font-family:verdana; font-size:20px;"></p>
<script>
function show()
{
var a=[Link]
[Link]("display").innerHTML="Entered integer value is:"+a
}
</script>
</body>
</html>
Output:
Example11: Write a javascript program to accept two integers and display
them.
Design
Program: [Link]
<!DOCTYPE html>
<html>
<head>
<title> Displaying integers </title>
<style>
label{
font-family:arial black;
font-size:20;
}
</style>
</head>
<body>
<label> Enter first integer</label>
<input type="text" id="textbox1"><br><br>
<label> Enter second integer </label>
<input type="text" id="textbox2"><br><br>
<input type="submit" value="Display" onclick="show()">
<p id="display" style="font-family:verdana; font-size:20px;"></p>
<script>
function show()
{
var a=[Link]
var b=[Link]
[Link]("display").innerHTML="First integer number
is:"+a+"<br><br>"+"Second integer number is:"+b
}
</script>
</body>
</html>
Output:
Example12: Write javascript program to accept two integers and display its
sum.
Design
Program: [Link]
<!DOCTYPE html>
<html>
<head>
<title> Addition of two integers </title>
</head>
<body>
<label> Enter first integer: </label>
<input type="text" id="textbox1"><br><br>
<label> Enter second integer: </label>
<input type="text" id="textbox2"><br><br>
<label>Addition of two integers:</label>
<input type="text" id="textbox3" disabled="true"><br><br>
<input type="submit" value="Addition" onclick="addition()"><br><br>
<script>
function addition()
{
var a=parseInt([Link])
var b=parseInt([Link])
var c=a+b
[Link]("textbox3").value=c
}
</script>
</body>
</html>
Output
Homework:
Interview questions:
1) What is a label?
2) What is a textbox?
3) How to give style to label?
4) How to disable one textbox?
Task1: Design a web page to accept Student details and display them
Student Details: Student ID, Student Name , Student address, student course,
student email ID, student phone number
Task2: Design a web page to accept employee details and display them
Employee Details: Emp ID, Emp Name, Emp Salary
Task3: Design a web page to accept four integer numbers and perform
addition operation and display the result in textbox
Task4: Design a web page to accept three float numbers and perform addition
operation and display the result in textbox