CSS QB Slove Sample Paper
CSS QB Slove Sample Paper
<html>
<body>
<h2>The Navigator Object</h2>
<p>The userAgent property returns the user-agent header sent by the browser to the server:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =navigator.userAgent
</script>
</body>
</html>
<body>
OR
<html>
<body>
<h2>Identify the running browser</h2>
<script>
document.getElementById("demo").innerHTML = "Running browser name is " +
navigator.appName;
document.getElementById("demo").innerHTML = "Running browser version is " +
navigator.appVersion;
document.getElementById("demo").innerHTML = "Running browser Application code is " +
navigator.appCodeName;
document.getElementById("demo").innerHTML = "Running browser language is " +
navigator.language;
</script>
</body></html>
<html>
<head><title> Window Properties </title>
<script language="javascript">
arr = Object.getOwnPropertyNames(window).sort();
for(i in arr)
{
document.write(arr[i]+"<br>");
}
</script>
<body>
</body>
</html>
Here,
The Object.getOwnPropertyNames() method returns an array of all properties found in the given
object. We have passed window as an object, hence it returns the properties of window object. A
for loop is used to loop through all the properties of window object and display them
3. Write a function that prompts the user for a color and uses what they select to set the background
color of the new webpage opened.
<html>
<body>
<h1>Hello World!</h1>
<button type="button" onclick="myFunction()">Set background color</button>
</body>
<head>
<script>
function myFunction()
{
var w=window.open("")
w.document.body.style.backgroundColor = "red";
}
</script>
</head>
</html>
4. Write a webpage that accepts Username and adharcard as input texts. When the user enters adhaarcard
number ,the JavaScript validates card number and diplays whether card number is valid or not. (Assume
valid adhaar card format to be nnnn.nnnn.nnnn or nnnn-nnnn-nnnn)
<html>
<head><title>Validation</title>
<script language="javascript">
function validate()
{
varadhar = document.myform.adhar.value;
var regex = /^\d{4}\.\d{4}\.\d{4}$|^\d{4}\-\d{4}\-\d{4}$/g
if(!regex.test(adhar))
{
alert("invalid adhar card number");
}
else
{
alert("Valid adhar card number");
}
}
</script>
</head>
<body>
<form name="myform" onSubmit="validate()">
Enter username : <input type="text name="user"><br><br>
Enter Adharcard : <input type="text" name="adhar"><br>
<input type="submit">
</form>
</body>
</html>
5. Write HTML Script that displays textboxes for accepting Name, middlename, Surname of the user and
a Submit button. Write proper JavaScript such that when the user clicks on submit button:
i) All texboxes must get disabled and change the color to “RED” and with respective labels.
<html>
<head>
<script>
function check()
{
var t1=document.getElementById('n')
var t2=document.getElementById("m")
var t3=document.getElementById("s")
t1.style.background="red"
t1.disabled="true"
t2.style.background="red"
t2.disabled="true"
t3.style.background="red"
t3.disabled="true"
}
</script>
</head>
<body>
<form name=f1 >
Name:<input type=text id=n>
<br>
<br>
Middle Name:<input type=text id=m>
<br>
<br>
Surname:<input type=text id=s>
<br>
<br>
<input type=button onclick=check() value=Submit>
<br>
<br>
</form>
</body>
</html>
ii) Constructs the mailID as <name>.<surname>@msbte.com and displays mail ID as message. (Ex. If user
enters Rajni as name and Pathak as surname mailID will be constructed as rajni.pathak@msbte.com)
<html>
<head>
<script>
function check()
{
var t1=document.f1.n.value
var t2=document.f1.s.value
msg=""+t1+"."+t2+"@msbte.com"
alert(msg)
}
</script>
</head>
<body>
<form name=f1 >
Name:<input type=text name=n>
<br>
<br>
Surname:<input type=text name=s>
<br>
<br>
<input type=button onclick=check() value=Submit>
<br>
<br>
</form>
</body>
</html>
6. 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>
<head>
<script type = "text/javascript">
function WriteCookie() {
if( document.myform.customer.value == "" ) {
alert("Enter some value!");
return;
}
cookievalue = escape(document.myform.customer.value) + ";";
document.cookie = "name=" + cookievalue;
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
</script>
</head>
<body>
<form name = "myform" action = "">
Enter name: <input type = "text" name = "customer"/>
<input type = "button" value = "Set Cookie" onchange = "WriteCookie();"/>
</form>
</body>
</html>
7. Write a script for creating following frame structure :
8. Write HTML Script that displays dropdown list containing options NewDelhi, Mumbai, Bangalore. Write
proper JavaScript such that when the user selects any options corresponding description of about 20 words
and image of the city appear in table which appears below on the same page.
9. Develop a JavaScript Program to Create Rotating Banner Ads with URL Links. Create a slideshow with
the group of four images, also simulate the next and previous transition between slides in your JavaScript
<html>
<script>
function ChangeBanner()
{
document.location.href=MyBannerLinks[banner]
}
function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0
}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<a href="javascript: ShowLinks()">
<imgsrc="banner1.jpg" width="900" height="120" name="ChangeBanner"/></a>
</center>
</body>
</html>
<html>
<head>
</head>
<frameset rows="20%,60%,20%">
<frame src="frm1.html">
<frame src="frm2.html" name=left>
<frame src="frm3.html" name=right>
</frameset>
</frameset>
</html>
11. Write a JavaScript that creates persistent cookies of Itemnames. Write appropriate HTML script for
the same
<html>
<head><title>Persistent Cooki</title>
<script language="javascript">
function createcookie()
{
var name=form1.nm.value;
var c1 = form1.s1.options[form1.s1.selectedIndex].value
var c2 = form1.s2.options[form1.s2.selectedIndex].value
var d = new Date();
d.setMonth(d.getMonth()+1);
cookievalue = "user="+name+",item1="+c1 +",item2="+c2+";expires="+d.toUTCString();
alert("Cookie Created");
}
</script>
</head>
<body>
<form name="form1" onsubmit="createcookie()">
Enter name:<input type="text" name="nm"><br>
Select item-1 <select name="s1">
<option> CD </option>
<option> DVD </option>
<option> BluRay</option>
<option> Pen drive </option>
</select>
Select item-2 <select name="s2">
<option> C Prog </option>
<option> C++ Prog</option>
<option> Java</option>
<option> DotNet </option>
</select>
<input type="Submit" value="Submit">
</form>
</body>
</html>
12. Write a JavaScript function to check whether a given value is valid IP value or not
<html>
<script>
var IPText = "192.168.8.12";
RegE = /^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$/
if(IPText.match(RegE))
alert('Valid IP');
else
alert('Invalid IP');
</script>
</html>
13. Write a JavaScript program to create rollover effect for three images
<html>
<body>
<h1>Image Rollover</h1>
<a><IMG src='apples.gif' height="92" width="70" border="0" onmouseover="src='apples.gif' "
onmouseout="src='redstar.gif' "></a>
<a><IMG src='ND1.png' height="92" width="70" border="0" onmouseover="src='ND1.png' "
onmouseout="src='M1.png' "></a>
<a><IMG src='M1.png' height="92" width="70" border="0" onmouseover="src='M1.png' "
onmouseout="src='B.png' "></a>
</body>
</body>
</html>
14. Write a JavaScript program that create a scrolling text on the status line of a window.
<html>
<head>
<title>Scrolling Text</title>
<script language="JavaScript">
var scrollPos = 0
var maxScroll = 100
var blanks = ""
function scrollText(text, milliseconds) {
window.setInterval("displayText('"+text+"')", milliseconds)
}
function displayText(text) {
window.defaultStatus = blanks + text
++scrollPos
blanks += " "
if(scrollPos > maxScroll) {
scrollPos = 0
blanks = ""
}
}
</script>
</head>
<body onload="scrollText('Watch this text scroll!!!', 300)">
<p>Watch the text scroll at the bottom of this window!</p>
</body>
</html>
Answers from QB
1. Give syntax of and explain the use of “with” statement/clause in JavaScript using suitable example
Ans:
Syntax:
with (object)
statement
introduces the properties of object as local variables in statement. Example (the braces are
optional for single statements, but it is recommended to add them):
Ex:
with({ first: "John" }) { alert("Hello "+first); }
Output: Hello John
There is one similar case in JavaScript where the properties of an object are turned into variables
and that is the global object window. All of its properties are global variables and vice versa. In
contrast, variables that are declared in statement are not added to object, but to the surrounding
function, where they still exist after leaving the block.
with({}) { var x = "abc"; }
x
Output: 'abc'
Ans: Also called a transient cookie, a cookie that is erased when the user closes the Web browser. The
session cookie is stored in temporary memory and is not retained after the browser is closed. Session
cookies do not collect information from the users computer. They typically will store information in the
form of a session identification that does not personally identify the user.
5. Construct regular expression for validating the phone number in following format only :(nnn)-nnnn-
nnnn OR nnn.nnnn.nnnn
Output:
a is odd number