Professional Documents
Culture Documents
Programs 3&4
Programs 3&4
JavaScript to create a dynamic web page with forms Use document. getElementByID,
document. getElementsByTagName
4. Open the main.js file and write the below content with the server-side JavaScript
code:
Code:
const fs = require('fs');
if (err) {
} else {
res.end(data);
});
});
server.listen(3000, () => {
});
5. Right-click on the project again, choose "New > File...", and name the file
index.html.
6. Open the index.html file and add the HTML and client-side JavaScript code:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<form id="myForm">
<button type="button"
onclick="submitForm()">Submit</button>
</form>
<script>
function submitForm() {
var inputValue =
document.getElementById('inputText').value;
</script>
</body>
</html>
Output:
Program 4: Clock App, Students will learn how to Use JS objects
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Clock App</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
#clock {
font-size: 2em;
</style>
</head>
<body>
<div id="clock"></div>
<script>
function Clock() {
this.updateTime = function () {
return `${hours}:${minutes}:${seconds}`;
};
this.displayTime = function () {
clockElement.textContent = this.updateTime();
};
this.startClock = function () {
setInterval(() => {
this.displayTime();
}, 1000);
};
}
// Create an instance of the Clock object
myClock.startClock();
</script>
</body>
</html>
Output: