Practical 6
Practical 6
21/5005
Solution:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Pet Information Form</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Pet Information Form</h1>
<form id="petForm">
<label for="petName">Name:</label>
<input type="text" id="petName" name="petName"
required>
<label for="petAge">Age:</label>
<input type="number" id="petAge" name="petAge"
required>
<label for="petType">Type:</label>
<input type="text" id="petType" name="petType"
required>
<button type="button"
onclick="submitForm()">Submit</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
CSS(Style.css)
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
}
form {
display: flex;
flex-direction: column;
}
label {
margin-top: 10px;
}
input {
margin-bottom: 10px;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
padding: 10px;
background-color: #4285f4;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #317ae2;
}
JAVASCRIPT(Script.js)
function submitForm() {
// Get form values
var petName =
document.getElementById('petName').value;
var petAge =
parseInt(document.getElementById('petAge').value);
var petWeight =
parseFloat(document.getElementById('petWeight').value);
var petType = document.getElementById('petType').value;
var petLikes = document.getElementById('petLikes').value;
// Create Pet object
var petObject = {
name: petName,
age: petAge,
weight: petWeight,
type: petType,
likes: petLikes
};