Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

Coding Question ut2 css

question bank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Coding Question ut2 css

question bank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Coding Question

Q.Write a javascript program to changing the contents of a window.?—2M


ANS:
<!DOCTYPE html>
<html>
<head>
<title>Changing the Content of Window</title>
</head>
<body>
<input type="button" value="Msg1" onclick="Msg1()">
<input type="button" value="Msg1" onclick="Msg2()">
<p id="para">Hello Javascript</p>
<script type="text/javascript">
function Msg1()
{
document.getElementById("para").innerHTML="Javascript Easy Language";
}
function Msg2()
{
document.getElementById("para").innerHTML="Javascript use for Validation";
}
</script>
</body>
</html>
Q.Write a program using sort method of array object.
ANS:
<!DOCTYPE html>
<html>
<head>
<title>sort method in js</title>
</head>
<body>
<script type="text/javascript">
var arr=[1,4,6,7,5,3];
arr.sort();
// after sort method
for(var i=0;i<arr.length;i++)
{
document.write(arr[i]+"<br>");

}
</script>
</body>
</html>
Q.Write a JavaScript program to create read, update and delete cookies.—4M
ANS:
<!DOCTYPE html>
<html>
<head>
<title>cookie</title>
</head>
<body>
<form name="myform">
Enter Username:<input type="text" name="uname"><br>
Enter Password:<input type="password" name="uPass"><br>
<input type="button" onclick="CreateCookie()" value="CrateCookie"><br>
<input type="button" onclick="ReadCookie()" value="ReadCookie"><br>
<input type="button" onclick="DeleteCookie()" value="DeleteCookie"><br>
<br>
Enter New Password:<input type="password" name="nPass"><br>
<input type="button" onclick="UpdateCookie()" value="UpdateCookie"><br>
<script type="text/javascript">
var x;
function CreateCookie()
{
var d=new Date();
d.setTime(d.getTime()+(7*24*60*60));
with(document.myform)
{
document.cookie="Username:"+uname.value+" Password:"+uPass.value; expires=+d.toGMTString();
x=document.cookie;
alert("Cookie Store Successfully");
}
}
function ReadCookie()
{
if(x==="")
{
alert("Cookie not Found");
}
else
{
alert(x);
}
}
function DeleteCookie()
{
var d=new Date();
d.setTime(d.getTime()-(7*24*60*60));
with(document.myform)
{
document.cookie="Username:"+uname.value+" Password:"+uPass.value; expires=+d.toGMTString();
x="";
alert("Cookie Delete Successfully");
}
}
function UpdateCookie()
{
var d=new Date();
d.setTime(d.getTime()+(7*24*60*60));
with(document.myform)
{
document.cookie="Username:"+uname.value+" Password:"+nPass.value; expires=+d.toGMTString();
x=document.cookie;
alert("Cookie Updpate Successfully");
}
}

</script>
</form>
</body>
</html>
Q. Write a JavaScript program to link banner advertisements to different URLs.-4M
ANS:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Banner Linking with JavaScript</title>
<script type="text/javascript">
var banners = [
{ image: "banner1.jpeg", url: "https://www.flipkart.com/" },
{ image: "banner2.png", url: "https://www.amazon.in/" },
{ image: "banner3.png", url: "https://www.shopsy.in/" },
{ image: "banner4.png", url: "https://www.meesho.com/" }
];

var currentIndex = 0;

function updateBanner()
{
var bannerImg = document.getElementById('bannerImage');
var bannerLink = document.getElementById('bannerLink');
bannerImg.src = banners[currentIndex].image;
bannerLink.href = banners[currentIndex].url;
currentIndex = (currentIndex + 1) % banners.length;
}

window.addEventListener('load', function()
{
updateBanner();
setInterval(updateBanner, 5000);
});
</script>
</head>
<body>
<center>
<a id="bannerLink" href="#" target="_blank">
<img id="bannerImage" src="" width="900" height="120" alt="Banner Advertisement" />
</a>
</center>
</body>
</html>
Q. Write a JavaScript program to validate email ID of the user using regular expression.-4M
ANS:
<!DOCTYPE html>
<html>
<head>
<title>Email Validation</title>
</head>
<body>
<form name="myform">
Enter Email:<input type="email" id="email"><br>
<input type="button" value="Check" onclick="ValidateEmail()">
</form>
<script type="text/javascript">
function ValidateEmail()
{
var email=document.getElementById("email").value;
var emailPattern=/^[a-z0-9]+@[a-z]+\.[a-z]{2,3}$/;
if(emailPattern.test(email))
{
alert("Corrected Email");
}
else
{
alert("Pls Provide Correct Email Like(example12@gmail.com");
}
}
</script>
</body>
</html>
Q. Write a JavaScript for the folding tree menu-4M
ANS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folding Tree Menu</title>
<style>
/* Style for the tree menu */
ul {
list-style-type: none;
margin: 0;
padding: 0;
}

li {
padding: 5px 10px;
cursor: pointer;
}

.nested {
display: none;
padding-left: 20px;
}

.active {
display: block;
}
</style>
</head>
<body>

<h2>Folding Tree Menu</h2>

<ul>
<li onclick="toggleMenu(event)">Item 1
<ul class="nested">
<li onclick="toggleMenu(event)">Sub-item 1.1
<ul class="nested">
<li onclick="toggleMenu(event)">Sub-item 1.1.1
<ul class="nested">
<li>Sub-item 1.1.1.2</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

<script>
function toggleMenu(event) {
// Prevent the click from bubbling up to the parent li
event.stopPropagation();

// Find the nested <ul> element


const nestedMenu = event.target.querySelector('ul');

// If there is a nested menu, toggle its visibility


if (nestedMenu) {
nestedMenu.classList.toggle('active');
}
}
</script>

</body>
</html>

Theory :open new window


<!DOCTYPE html>
<html>
<head>
<title>open window when click button</title>
</head>
<body>
<button onclick="openWin()">Open new Window</button>
<script type="text/javascript">
var myWindow;
function openWin()
{
myWindow=window.open("","myWindow","width=400,height=400");
myWindow.document.write("<p>Helloo Everyone welcome to new Window</p>");
}
</script>
</body>
</html>

You might also like