CSS Practice Test2 Ans
CSS Practice Test2 Ans
2 Marks
1. JavaScript to Design a Form to Accept Values for User ID & Password
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form name="loginForm">
<label for="password">Password:</label>
</form>
</body>
</html>
• Properties:
• Methods:
if (isNaN("Hello")) {
The location object contains information about the current URL and allows for navigation between
pages. It can be used to get the URL or parts of it, and to redirect the browser to another URL.
Deleted when the browser is Deleted only when the expiry date is met or manually
Deletion
closed removed
7. Form Events
• onmouseup: This event occurs when the mouse button is released over an element. It’s
typically used in combination with onmousedown.
• onblur: This event is triggered when an element loses focus, often used for validating input
fields when the user moves away from a form field.
Cookies are small pieces of data stored by a website on a user's device to remember information
about the user’s visit, such as login state or user preferences.
setTimeout(function() {
}, 3000);
setInterval(function() {
}, 2000);
1. HTTPS Encryption
2. Input Validation
3. XSS Protection
Explanation of CSP: CSP is a security feature that helps prevent cross-site scripting (XSS) attacks by
specifying which sources are allowed to load content on the webpage.
window.open("https://example.com", "_blank");
CSS Practice test 2 Answers
• Focus: The event when a window or input field gains focus, meaning it's active and ready for
input.
• Blur: The event when a window or input field loses focus, indicating it is no longer the active
element.
4 Marks
1. What is a Cookie? Explain Its Need. State Characteristics of Persistent Cookies.
Cookie:
A cookie is a small piece of data sent from a website and stored in the user's browser to remember
information between sessions, like login credentials or user preferences.
1. Longer Lifespan: They remain on the user’s device until a specified expiration date.
2. Stored on Disk: Persistent cookies are saved to the user's hard drive, unlike session cookies
stored in memory.
3. Multiple Sessions: They can track data across multiple sessions and browser restarts.
4. Custom Expiration: You can specify an expiration date after which the cookie will be deleted.
Read a Cookie:
function getCookie(name) {
return "";
1. HTTPS Encryption
2. Input Validation
<!DOCTYPE html>
<html>
<head>
</head>
<body>
CSS Practice test 2 Answers
<label for="gender">Gender:</label>
<label for="email">Email:</label>
<option value="BSc">B.Sc.</option>
<option value="BCom">B.Com</option>
<option value="BTech">B.Tech</option>
</select><br><br>
</form>
</body>
</html>
// Create a Cookie
// Read a Cookie
function readCookie(name) {
return "";
// Delete a Cookie
function deleteCookie(name) {
// Usage
console.log(readCookie("user")); // Vedant
deleteCookie("user");
CSS Practice test 2 Answers
1. action: Specifies where to send the form data when the form is submitted (e.g., URL).
2. method: Specifies how to send form data. Can be either GET or POST.
3. enctype: Specifies how form data should be encoded when submitted (e.g., application/x-
www-form-urlencoded or multipart/form-data for file uploads).
4. target: Specifies where to display the response after form submission (e.g., _blank, _self).
Visibility Data is appended in URL and visible Data is sent in the body, hidden
Data Length Limited due to URL length restrictions No restrictions on data size
Usage Used for non-sensitive data Used for sensitive data (e.g., passwords)
Example:
• GET Method:
<input type="submit">
</form>
• POST Method:
<input type="submit">
</form>
CSS Practice test 2 Answers
6 Marks
1. Evaluating a Radio Button in JavaScript with Example
To evaluate a radio button in JavaScript, you need to determine which radio button has been selected
from a group of buttons with the same name. This can be done by looping through the group of radio
buttons and checking if any are checked.
Example:
<!DOCTYPE html>
<html>
<head>
<script>
function evaluateRadioButton() {
if (radios[i].checked) {
return;
</script>
</head>
<body>
<form>
<label>Gender:</label><br>
</form>
</body>
</html>
Explanation:
• The getElementsByName('gender') method is used to retrieve all radio buttons with the
name gender.
• The loop checks if any radio button is checked by evaluating radios[i].checked. If it finds one,
it displays its value.
• If none of the radio buttons are checked, it alerts the user to select one.
Writing a Cookie
To write a cookie in JavaScript, you use the document.cookie property. You can specify the name,
value, and other options like expiration date and path.
Example:
// Create a cookie named "username" with the value "Vedant", lasting 7 days
Reading a Cookie
To read a cookie, you access document.cookie, which returns a string of all cookies. You can then
search for the desired cookie using its name.
Example:
function getCookie(name) {
Explanation:
• Writing a cookie: setCookie() function creates a cookie by setting its name, value, and
expiration (in days). It uses the document.cookie property.
• Reading a cookie: getCookie() searches for a cookie by its name by splitting the
document.cookie string, and if found, it returns the value of that cookie.
<!DOCTYPE html>
<html>
<head>
<title>Cookie Example</title>
function getCookie(name) {
}}return "";
function handleCookies() {
if (username != "") {
} else {
}}
</script>
</head>
<body>
</body>
</html>