User Id: Password
User Id: Password
### **1. Write a Javascript to design a form to accept values for user ID & password:**
```html
<form>
</form>
```
### **2. State any two properties and methods of location object:**
- **Properties:**
- **Methods:**
### **3. Enlist & explain the use of any two Intrinsic JavaScript Functions:**
```js
```
2. **isNaN()**: Checks if a value is NaN (Not a Number).
```js
```
The **location object** contains information about the current URL and provides methods to
manipulate the browser location. It includes properties such as `href`, `protocol`, `hostname`, and
methods such as `reload()`, `assign()` to navigate or refresh the browser page.
### **5. Enlist any four mouse events with their use:**
- **Session cookies**: These are temporary cookies stored in the browser’s memory and deleted once
the browser is closed.
- **Persistent cookies**: These cookies remain on the user’s device for a specified time and can be used
to track user behavior across multiple sessions.
- **onblur**: Triggered when an element loses focus (e.g., when moving away from an input field).
### **8. Write a JavaScript program to change the contents of a window:**
```html
<script>
Function changeContent() {
</script>
```
### **9. Write a JavaScript syntax for accessing elements of another child window:**
```js
```
1. **input**: Used for text input fields, password fields, checkboxes, radio buttons, etc.
4. **button**: Used to create clickable buttons that trigger actions or submit forms.
### **12. State any two properties and methods of location object (Repeated):**
- **Properties:**
- **Methods:**
1. `location.replace()` – Replaces the current document with a new one without storing the history.
```js
```
### **14. Write a JavaScript to design a form to accept values for user ID & password (Repeated):**
Refer to answer 1.
### **15. Differentiate between session cookies and persistent cookies (Repeated):**
Refer to answer 6.
### **16. Write a JavaScript syntax to access elements of another child window (Repeated):**
Refer to answer 9.
### **17. Write a JavaScript program to change the contents of a window (Repeated):**
Refer to answer 8.
### **18. Write the syntax and explain the use of the following methods of JavaScript Timing Event:**
```js
```
```js
```
### **19. List ways of Protecting your webpage and describe any one of them:**
```js
Window.open(http://www.example.com, “_blank”);
```
### **21. What is the meaning of windows Focus and windows Blur:**
- **Window Focus**: When a window becomes the active window (i.e., user is interacting with it).
- **Window Blur**: When the window loses focus, meaning the user switches to another window or
tab.
Refer to answer 4.
Here’s a simple HTML webpage with a form for entering a username and password. The form data
(username and password) is stored as cookies using a JavaScript function:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Form with Cookies</title>
</head>
<body>
<h2>Login Form</h2>
<form onsubmit="storeCookies()">
</form>
<script>
function storeCookies() {
</script>
</body>
</html>
```
### Explanation:
- The form contains two input fields: one for the **username** and another for the **password**.
- When the user submits the form, the JavaScript function `storeCookies()` is triggered.
- The function stores the username and password as cookies with a **7-day expiration** (`max-age` is
set to 7 days).
You can expand the code by adding validation or encrypting the password for added security if needed.
Let’s answer all the questions based on the image you’ve uploaded.
Here is the HTML and JavaScript code for the calculator that performs addition, subtraction, and
multiplication based on user input.
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Simple Calculator</title>
<script>
Function calculate(operation) {
Let result;
If (operation === ‘add’) {
Alert(“Result: “ + result);
</script>
</head>
<body>
<h2>Simple Calculator</h2>
<form>
</form>
</body>
</html>
```
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Email Generator</title>
<script>
Function createEmail() {
</script>
</head>
<body>
<h2>Email Generator</h2>
<form>
</form>
</body>
</html>
```
**Cookie**: A cookie is a small piece of data stored on the user’s device by the web browser. Cookies
are used to remember information about the user, such as login details or preferences.
**Need**: Cookies are essential for maintaining sessions, user preferences, and tracking user activities
across web pages.
- Used for long-term tracking and remembering user preferences across sessions.
```html
<script>
Window.onload = function() {
}
// Opens another popup when the page unloads
Window.onunload = function() {
</script>
```
### **6. HTML Script to Display Laptop Brands and Image on Hover**
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Laptop Brands</title>
<style>
.image-box {
Width: 200px;
Height: 150px;
Text-align: center;
Line-height: 150px;
</style>
<script>
Function showImage(brand) {
} else {
imageBox.innerHTML = “Image”;
</script>
</head>
<body>
<ul>
<li onmouseover=”showImage(‘lenovo’)”>Lenovo</li>
<li onmouseover=”showImage(‘hp’)”>HP</li>
<li onmouseover=”showImage(‘dell’)”>Dell</li>
</ul>
</body>
</html>
```
This script will display the respective laptop image when you hover over the brand names in the list.
Make sure you have images named `lenovo.jpg`, `hp.jpg`, and `dell.jpg` for the hover effect to work.
1. **HTTPS (SSL/TLS)**: Ensures encrypted communication between the user and the server.
2. **Content Security Policy (CSP)**: Helps prevent cross-site scripting (XSS) and data injection attacks.
3. **Input Validation and Sanitization**: Ensures that user inputs are properly validated to prevent SQL
injection and other attacks.
5. **Obfuscate JavaScript Code**: Makes it harder for users to read or manipulate the website’s
JavaScript code.
**Example of HTTPS**:
SSL/TLS encrypts data transmitted between the client and server, providing security against
eavesdropping and man-in-the-middle attacks. It authenticates the server to the client and ensures the
integrity of the content.
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Image Slideshow</title>
<script>
Let currentImageIndex = 0;
imgElement.src = images[index];
Function nextImage() {
showImage(currentImageIndex);
Function prevImage() {
showImage(currentImageIndex);
Window.onload = function() {
showImage(currentImageIndex);
};
</script>
</head>
<body>
<h2>Image Slideshow</h2>
<br>
<button onclick=”prevImage()”>Previous</button>
<button onclick=”nextImage()”>Next</button>
</body>
</html>
```
### **9. Create and Read Persistent Cookies in JavaScript**
```javascript
If (days) {
Date.setTime(date.getTime() + (days*24*60*60*1000));
```
**Reading a Cookie:**
```javascript
Function getCookie(name) {
Const ca = document.cookie.split(‘;’);
Let c = ca[i];
}
Return null;
```
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
</head>
<body>
Course:
<option value=”BSc”>BSc</option>
<option value=”BA”>BA</option>
<option value=”BCom”>BCom</option>
</select><br><br>
</body>
</html>
```
### **11. JavaScript Program to Create, Read, Update, and Delete Cookies**
```javascript
// Create a cookie
If (days) {
Date.setTime(date.getTime() + (days*24*60*60*1000));
// Read a cookie
Function getCookie(name) {
Const ca = document.cookie.split(‘;’);
Let c = ca[i];
}
Return null;
// Delete a cookie
Function deleteCookie(name) {
```
2. **method**: The HTTP method (GET or POST) used to submit the form.
3. **enctype**: Specifies how the form data should be encoded when submitted.
4. **target**: Specifies where to display the response after submitting the form (e.g., `_blank` for a new
tab).
- **GET**:
```html
</form>
```
- **POST**:
**Example**:
```html
</form>
```
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<script>
Function openWindow() {
</script>
</head>
<body>
</body>
</html>
```
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<title>Item Cookie</title>
<script>
Function setItemCookie(itemName) {
</script>
</head>
<body>
</body>
</html>
```
This code stores the username and password as cookies when submitted.
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<script>
Function storeCookies() {
</script>
</head>
<body>
<h2>Login Form</h2>
Password