CSS Solved QB
CSS Solved QB
Output:
1
b) Give regular expression for matching digits and non-digits.
Ans :
<html>
<head>
<script type = "text/javascript">
var p =/\d/;
function testMatch()
{
var str = textfield.value;
if(p.test(str))
{
window.alert("The string " +str+"contains digit.");
}
else {
window.alert("The string" +str+"does not contains digits.");
}
}
</script>
</head>
<body>
<h3><p>Checking the availability of character in given range.</p></h3>
Enter the string: <input type="text" id="textfield"/>
<input type= "button" value="check" onclick="testMatch();"/>
</body>
</html>
Output:
2
<html>
<head>
<script>
img_array=new Array("https://media.istockphoto.com/id/1403500817/photo/the-craggies-in-
the-blue-ridge-mountains.jpg?s=612x612&w=0&k=20&c=N-
pGA8OClRVDzRfj_9AqANnOaDS3devZWwrQNwZuDSk=","https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcTbpdV5eKcBMzjs7ltDev4YxvWvnNxcFk7wUg&s
");
img=0;
function displayImg(num)
{
img=img+num;
if(img>img_array.length-1)
{
img=0;
}
if(img<0)
{
img=img_array.length-1;
}
document.Slide.src=img_array[img];
}
</script>
</head>
<body>
<img src ="https://media.istockphoto.com/id/1403500817/photo/the-craggies-in-the-blue-
ridge-mountains.jpg?s=612x612&w=0&k=20&c=N-
pGA8OClRVDzRfj_9AqANnOaDS3devZWwrQNwZuDSk=" width="400" height="200"
name="Slide"/>
<br>
<input type="button" value="Previous" onclick="displayImg(-1)">
<input type="button" value="Next" onclick="displayImg(1)">
</body>
</html>
Output:
3
d) Explain the concept of timers with its methods.
Ans :
In JavaScript, a timer is created to execute a task or any function at a particular time. Basically,
the timer is used to delay the execution of the program or to execute the JavaScript code in a
regular time interval. With the help of timer, we can delay the execution of the code. So, the
code does not complete it's execution at the same time when an event triggers or page loads.
1.setTimeout()
The setTimeout() function helps the users to delay the execution of code. The setTimeout()
method accepts two parameters in which one is a user-defined function, and another is the time
parameter to delay the execution.
Syntax : setTimeout(function, milliseconds)
2. setInterval()
It executes the specified function repeatedly after a time interval. Or we can simply say that a
function is executed repeatedly after a specific amount of time provided by the user in this
function.
Ans:
<html>
<body>
<frameset cols="50%,25%,25%,50%">
<frame style="background-color:red">
<frame style="background-color:blue">
<frame style="background-color:green">
<frame style="background-color:pink">
</frameset>
</body>
</html>
f) Write a JavaScript program to create a slide show with the group of six images, also
simulate the next and previous transition between slides in your JavaScript.
Ans :
<html>
<head>
<script>
4
pics = new
Array('https://i.pinimg.com/736x/2e/cf/06/2ecf067a2069128f44d75d25a32e219e.jpg' ,
'https://cms.interiorcompany.com/wp-content/uploads/2024/01/lotus-beautiful-flowers.jpg' ,
'https://images.pexels.com/photos/532168/pexels-photo-
532168.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500','https://cdn.shopify.com/s/files/1/
0085/2344/8371/files/lily-flower-garden_480x480.jpg?v=1692171975','https://m.media-
amazon.com/images/I/41SqS4Od+DL._AC_UF1000,1000_QL80_.jpg','https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcScqrzXypb1MV4osieK6yvt3C96jAaS8fhoDw&s');
count = 0;
function slideshow(status)
{
if (document.images)
{
count = count + status;
if (count > (pics.length - 1))
{
count = 0;
}
if (count < 0)
{
count = pics.length - 1;
}
document.img1.src = pics[count];
}
}
</script>
</head>
<body>
<img src="https://cms.interiorcompany.com/wp-content/uploads/2024/01/lotus-beautiful-
flowers.jpg" width="200" name="img1">
<br>
<input type="button" value="Next" onclick="slideshow(1)">
<input type="button" value="Back" onclick="slideshow(-1)">
</body>
</html>
Output :
5
Q.2 Attempt any THREE.
function openWindow()
{
newWindow = window.open('https://www.example.com', 'exampleWindow',
'width=600,height=400');
}
function scrollWindow()
{
if (newWindow)
{
newWindow.scrollTo(0, 200);
}
}
function closeWindow() {
if (newWindow) {
newWindow.close();
}
}
</script>
</head>
<body>
6
<html>
<head>
<title>Image Rollover</title>
<script>
function display1()
{
document.getElementById("fruit").src = 'https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcRtkzZMTh_n9DE3CznuCnA8wVdQI7IQT9sDng&
s';
document.getElementById("para").innerHTML = "Trees of apple are larger than trees of
pineapple.";
}
function display2()
{
document.getElementById("fruit").src = 'https://berrydalefoods.com/wp-
content/uploads/2021/06/Pine-apple.jpg';
document.getElementById("para").innerHTML = "Trees of pineapple are smaller than trees
of apple.";
}
</script>
</head>
<body>
<h2>Image Rollover</h2>
<a onmouseover="display1()">
<h3>Apple</h3>
</a>
<a onmouseover="display2()">
<h3>Pineapple</h3>
</a>
<img src="https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcRtkzZMTh_n9DE3CznuCnA8wVdQI7IQT9sDng&
s" id="fruit" width="200">
<p id="para">Trees of apple are larger than trees of pineapple.</p>
</body>
</html>
Output :
7
c) List ways of protecting your webpage and describe any one of them
Ans :
Ways of protecting Web Page:
1)Hiding your source code
2)Disabling the right MouseButton
3) Hiding JavaScript
4) Concealing E-mail address.
The source code for your web page—including your JavaScript—is stored in the cache,
the part of computer memory where the browser stores web pages that were requested by
the visitor. A sophisticated visitor can access the cache and thereby gain access to the web
page source code. However, you can place obstacles in the way of a potential peeker. First,
you can disable use of the right mouse button on your site so the visitor can't access the
View Source menu option on the context menu. This hides both your HTML code and your
JavaScript from the visitor. Nevertheless, the visitor can still use the View menu's Source
option to display your source code. In addition, you can store your JavaScript on your web
server instead of building it into your web page. The browser calls the JavaScript from the
web server when it is needed by your web page. Using this method, the JavaScript isn't
visible to the visitor, even if the visitor views the source code for the web page.
The following example shows you how to disable the visitor's right mouse button while the
browser displays your web page. All the action occurs in the JavaScript that is defined in
the tag of the web page. The JavaScript begins by defining the BreakInDetected() function.
This function is called any time the visitor clicks the right mouse button while the web page
is displayed. It displays a security violation message in a dialog box whenever a visitor
clicks the right mouse button The BreakInDetected() function is called if the visitor clicks
any button other than the left mouse button.
Example:
<html>
<head>
<script>
document.addEventListener('contextmenu',event=> event preventDefault());
</script>
</head>
<body>
<h3><p>Disabling thee right click of mouse button.</p></h3>
</body>
</html>
8
d) Write a JavaScript program to validate phone number and email ID of the user using
regular expression..
Ans :
<html>
<head>
<title>Form Validation</title>
<script type="text/javascript">
function validate()
{
if (document.myForm.EMail.value == "")
{
alert("Please provide your email!");
document.myForm.EMail.focus();
return false;
}
if (!/\S+@\S+\.\S+/.test(document.myForm.EMail.value))
{
alert("Please enter a correct email ID");
return false;
}
if (document.myForm.Phone.value == "")
{
alert("Please provide your phone number!");
document.myForm.Phone.focus();
return false;
}
if (!/^\d{10,15}$/.test(document.myForm.Phone.value))
{
alert("Please enter a valid phone number!");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return(validate());">
<label for="email">Email</label>
9
<input type="text" id="email" name="EMail" /><br><br>
Output:
10