CSS CT2 Combined
CSS CT2 Combined
Output: You are using Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Code/1.73.1 Chrome/102.0.5005.167 Electron/19.0.17 Safari/537.36
3. State what is a regular expression? Explain its meaning with the help of a suitable example.
• A regular expression is a sequence of characters that forms a specific search pattern.
• The search pattern can be used for operations like text search, text replacement and
validation operations.
• A regular expression can be a single character, a string or more complex pattern.
• A regular expression language is written between two “/” forward slashes.
• The language of regular expression consists of quantifiers, meta characters and character
classes.
• There are two ways a regular expression can be created. One is by using the literals and
other is by using the RegExp() constructor.
• Syntax for regexp is as follows:
o var pattern = /expression/
o var pattern = new RegExp(/expression/)
• Example:
<html>
<script>
let text = "Client Side Scripting";
let n = text.search(/Side/i);
//i is a modifier (modifies the search to be case-insensitive)
document.write(n);
</script>
</html>
Output: 7
4. Write a webpage that accepts Username and Aadhar card as input texts. When the user
enters Aadhar card number, the JavaScript validates card number and displays whether
card number is valid or not. (Assume valid Aadhar card format to be nnnn.nnnn.nnnn or
nnnn-nnnn-nnnn).
<html>
<body>
<script>
var username = prompt("Enter Username");
var aadhaar = prompt("Enter Aadhaar No.");
var pattern1 = /^\d{4,4}[-]\d{4,4}[-]\d{4,4}[-]\d{4,4}$/;
//format NNNN-NNNN-NNNN-NNNN
var pattern2 = /^\d{4,4}[.]\d{4,4}[.]\d{4,4}[.]\d{4,4}$/;
//format NNNN.NNNN.NNNN.NNNN
// \d matches any digit, {4,4} specifies minimum and max length,
// ^ specifies match the beginning, $ specifies match the end
var result = pattern1.test(aadhaar) || pattern2.test(aadhaar)
if (result) {
alert("Aadhar No. is Valid")
}
else
alert("Aadhar No. is Invalid")
</script>
</body>
</html>
5. Write the syntax of and explain use of following methods of JavaScript Timing Event.
a. setTimeout()
• The setTimeout() method is used call a function after a number of milliseconds.
• The function is called only once after the specified time.
• The clearTimeout() can be used to prevent the function from starting
• The syntax for setTimeout() is:
var myTimeout = setTimeout(functionname(), time);
b. setInterval()
• The setInterval() method is used call a function repeatedly after specified interval.
• The function is called again and again after the specific time interval.
• The clearInterval() can be used to stop the timer.
• The syntax for setInterval() is:
var myInterval= setInterval(functionname(), time);
6. Write a JavaScript that displays all properties of window object. Explain the code.
<html>
<body>
<button onclick="createWindow()">Open a Window</button>
<script>
function createWindow() {
var win = window.open("", "My Window", "width=500,
height=200,top=100,left=100");
// window properties
var isclose = win.closed;
var name = win.name;
// writing in the current document
document.write(isclose + "<br>");
document.write(name + "<br>");
document.write(win.screenY + "<br>");
document.write(win.screenX + "<br>");
// we can access the new window document like this
win.document.write("Hello World!");
}
</script>
</body>
</html>
7. List ways of Protecting your webpage and describe any one of them.
The Ways of protecting Web Page are:
1. Hiding your source code
2. Disabling the right MouseButton
3. Hiding JavaScript
4. Concealing E-mail address.
8. Write a webpage that displays a form that contains an input for Username and password.
User is prompted to enter the input and password and password becomes value of the
cookie. Write The JavaScript function for storing the cookie. It gets executed when the
password changes.
<html>
<body onload="getCookie()">
<form name>
<label> Username: </label>
<input type="text" id="username" /><br><br>
<label> Password: </label>
<input type="password" id="password" /><br><br>
<input type="button" value="Register" onclick="setCookie()" />
<p id="content"></p>
</body>
<script>
function setCookie() {
document.cookie=
"password=" + document.getElementById("password").value + ";";
getCookie();
}
function getCookie() {
var cookiearray = document.cookie;
cookiearray = cookiearray.split("=");
if (cookiearray[0] == "password")
document.getElementById("content").innerHTML = "Last used
password: " + cookiearray[1];
else
document.getElementById("content").innerHTML = "Cookie not
found"
}
</script>
</html>
Fruits, Flowers and Cities are links to the webpage fruits.html, flowers.html, cities.html
respectively. When these links are clicked corresponding data appears in "FRAME3".
• index.html
<html>
<frameset rows="10%,90%">
<frame src="frame1.html" />
<frameset cols="50%, 50%">
<frame src="frame2.html" />
<frame name="frame3" />
</frameset>
</frameset>
</html>
• frame1.html
<html>
<body>
<h1>My Website</ </body>
</html>
• frame2.html
<html>
<body>
<li onclick="parent.frame3.location.href='fruits.html'">Fruits</li>
<li onclick="parent.frame3.location.href='flowers.html'">Flowers</li>
<li onclick="parent.frame3.location.href='cities.html'">Cities</li>
</body>
</html>
• fruits.html
<html>
<body>
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
</body>
</html>
//Create simiplar html pages for flowers and cities
10. Develop a JavaScript Program to Create Rotating Banner Ads with URL Links.
<html>
<body onload="rotate()">
<a id="link">
<img src="img1.png" id="img" height="100%" width="100%">
</a>
<script>
function rotate() {
count++; if (count > pics.length - 1) {
count = 0;
}
document.getElementById("img").src = pics[count][0];
document.getElementById("link").href = pics[count][1];
setTimeout("rotate()", 2000)
}
</script>
</body>
</html>
11. Create a slideshow with the group of four images, also simulate the next and previous
transition between slides in your JavaScript
<html>
<body>
<img src="img1.png" id="img" height="50%" width="70%"><br>
<input type="button" value="Previous" onclick="slideshow(-1)">
<input type="button" value="Next" onclick="slideshow(1)">
<script>
var pics = ["img1.png", "img2.png", "img3.png", "img4.png"];
var count = 0;
function slideshow(status) {
count = count + status;
if (count > pics.length - 1) {
count = 0;
}
if (count < 0) {
count = pics.length - 1;
}
document.getElementById("img").src = pics[count];
}
</script>
</body>
</html>
CSS 20M SAMPLE PAPER SOLUTION:
Q.1) Attempt any FOUR. 08 Marks
a) Design the frameset tag for following frame layout:
<!DOCTYPE html>
<html>
<frameset rows="20%,55%,25%">
<frame src="frame1.html" />
<frame src="frame2.html"/>
<frame src="frame3.html"/>
</frameset>
</html>
c) Construct regular expression for validating the phone number in following format
only :(nnn)-nnnn-nnnn OR nnn.nnnn.nnnn
<!DOCTYPE html>
<html>
<body>
<script>
var phoneno = prompt("Enter Phone No.");
var pattern1 = /^[(]\d{3,3}[)][-]\d{4,4}[-]\d{4,4}$/;
//format (nnn)-nnnn-nnnn
var pattern2 = /^\d{3,3}[.]\d{4,4}[.]\d{4,4}$/;
//format NNN.NNNN.NNNN
// \d matches any digit, {4,4} specifies minimum and max length,
// ^ specifies match the beginning, $ specifies match the end
var result = pattern1.test(phoneno) || pattern2.test(phoneno)
if(result)
{
alert("Phone No. is Valid")
}
else
alert("Phone No. is Invalid")
</script>
</body>
</html>
Q.2) Attempt any THREE. 12 Marks
a) Write a JavaScript that creates a persistent cookies of Itemnames. Write appropriate
HTML script for the same.
<!DOCTYPE html>
<html>
<body onload="getCookie()">
<form name>
<label> Enter Name: </label>
<input type="text" id="name" /><br><br>
<input type="button" value="Set" onclick="setCookie()" />
<p id="content"></p>
<script>
function setCookie()
{
//or
// var expires = “Sat, 17 Dec 2022 00:00:00 GMT”
// directly specify date and time in UTC format if you don’t want to
use Date constructors.
getCookie();
}
function getCookie() {
cookiearray = cookiearray.split("=");
if (cookiearray[0] == "itemnames")
else
document.getElementById("content").innerHTML = "Cookie not found"
}
</script>
</form>
</body>
</html>
b) Write a JavaScript function to check whether a given value is valid IP value or not.
<!DOCTYPE html>
<html>
<body>
<script>
var ipaddr = prompt("Enter IP Address:");
var pattern = /^\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}$/;
// format for ip range 0.0.0.0 to 255.255.255.255
var result = pattern.test(ipaddr)
if(result)
{
alert("IP Address is Valid")
}
else
alert("IP Address is Invalid")
</script>
</body>
</html>
window.status=
msg.substring(pos,msg.length)+spacer+msg
.substring(0,pos);
pos++;
if(pos>msg.length)
pos=0;
window.setTimeout("ScrollMessage()",100);
}
ScrollMessage();
</script>
</head>
<body>
<p>Scrolling Message</p>
</body>
</html>
MENUBAR PROGRAM
<!DOCTYPE html>
<html>
<body>
Select the page to navigate:
<select onchange="navigate(this)">
<option value="">---Select---</option> //this is needed
<option value="https://www.google.com">Google</option>
<option value="https://www.yahoo.com">Yahoo</option>
<option value="https://www.bing.com">Bing</option>
</select>
<script>
function navigate(menu) {
window.location = menu.options[menu.selectedIndex].value;
}
</script>
</body>
</html>