Css-Internal and External Programs_2024
Css-Internal and External Programs_2024
1. Write a JavaScript program which accepts N as input and print first N odd numbers.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fun(str)
{
var num=Number(str);
var i,j,k,count;
document.write("<h3>"+" The odd numbers are..."+"</h3>");
for(i=0;i<=num;i++)
{
if(i%2!=0)
document.write(" "+i);
}
}
</script>
</head>
<body>
<script type="text/javascript">
var input_str=prompt("Enter some number","");
fun(input_str);
</script>
</body>
</html>
2. Write a JavaScript for sorting the array elements.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = ["Sanjay","Aman","Rehman","Karan"];
document.write(a + "<br><br>");
a.sort();
document.write(a);
</script>
</head>
<body>
</body>
</html>
3. Develop JavaScript to implement Strings (any 4 methods).
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var str = "JavaScript is a Great is Language";
var str2 = "Hello";
var str3 = 50;
document.write("Original string::"+str+"<br>");
var a = str.charAt(3); /* CharAt Method */
document.write("char at method 3::"+ a + "<br>");
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function A()
</script>
</head>
<body onload="A()">
</script>
</body>
</html>
<!DOCTYPE html>
<html >
<head>
<title>My Page</title>
</head>
<body>
<form>
<b>Select Gender:</b><br/><br/>
<b>Select Class:</b><br/><br/>
</div>
<br/><br/><br/>
</form>
</body>
</html>
6. Write JavaScript that demonstrate mouse events.
<html>
<body>
<form>
</form>
<script>
function my_fun()
</script>
</body>
</html>
Or
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Or
<html>
<head>
{ elmnt.style.color = clr;
</script>
</head>
<body>
</h2>
</body>
</html>
7. Write a JavaScript to create three categories - Fruit, Flower and Color. Based on the
selection of category, the item, in the option list must get changed.
<html>
<head>
<script type="text/javascript">
function MySelection(val)
with(document.forms.myform)
if(val==1)
choices[0].text="Mango"
choices[0].value=1
choices[1].text="Orange"
choices[1].value=2
choices[2].text="Banana"
choices[2].value=3
if(val==2)
choices[0].text="Rose"
choices[0].value=1
choices[1].text="Jasmine"
choices[1].value=2
choices[2].text="Lotus"
choices[2].value=3
if(val==3)
choices[0].text="Red"
choices[0].value=1
choices[1].text="Green"
choices[1].value=2
choices[2].text="Blue"
choices[2].value=3
</script>
</head>
<body>
<form name="myform">
<br/><br/>
<select name="choices">
<option Value=1>Mango
<option Value=2>Orange
<option Value=3>Banana
</select>
</form>
</body>
</html>
8 Write a JavaScript to create a pull – down menu with three options [Google,MSBTE,
Yahoo] once the user will select one of the options then user will be Redirected to
that site.
<!DOCTYPE>
<html>
<head>
<title>Pull Down Menu</title>
<script language="Javascript">
function Display(Ch)
{
MyPage = Ch.options[Ch.selectedIndex].value
if (MyPage != "")
{
window.location = MyPage
}
}
</script>
</head>
<body onload="document.Form1.MyMenu.selectedIndex=0">
<form action="" name="Form1">
<select name="MyMenu" onchange="Display(this)">
<option>Select option</option>
<option value="https://www.google.com/">Google</option>
<option value="https://msbte.org.in/"> MSBTE</option>
<option value="https://in.search.yahoo.com/?fr2=inr"> Yahoo</option>
</select>
</form>
</body>
</html>
var getCookie=document.cookie;
document.write(getCookie)//read cookies
document.cookie= "sgm=polytechnic;expires=Mon, 31 Oct 2022 11:00:00
UTC;"//delete cookies
document.write(getCookie)//read
console.log(getCookie);
</script>
</html>
2.SetInterval()
<!DOCTYPE html>
<html>
<body>
<p id="ID"></p>
<script type="text/javascript">
var t=setInterval(MyFunction,2000);
function MyFunction()
{
document.getElementById("ID").innerHTML+="<p>Welcome User!!!</p>";
}
</script>
</body>
</html>
14. Write a program for mobile number validation using regular expression
<html>
<head>
<script type="text/javascript">
var re = /^[7-9][0-9]{9}$/;
function testMatch()
{
var str=textfield.value;
if(re.test(str))
{
alert("Your mobile number is " + str);
}
else
{
alert("Please enter correct mobile numebr");
}
}
</script>
</head>
<body>
<h2>Checking valid mobile number</h2>
</body>
</html>
15. Write a JavaScript in which when user rolls over the name of fruit, the
corresponding image should be displayed. For instance - if user rolls over the text
"Mango"; the image of Mango should be displayed
<!DOCTYPE html>
<html>
<head>
<title>Rollover Text</title>
</head>
<body>
<table>
<tr>
<td>
<a>
<IMG src="Mango.jpg" name="fruit">
</a>
<a onmouseover="document.fruit.src=' Mango.jpg'">
<b><u>Mango</u></b>
</a>
<br/><br/><br/><br/>
<a onmouseover="document.fruit.src='Orange.jpg'">
<b><u>Orange</u></b>
</a>
<br/><br/><br/><br/>
<a onmouseover="document.fruit.src='banana.jpg'">
<b><u>Banana</u></b>
</a>
</td>
</tr>
</table>
</body>
</html>
16. Create a slideshow with the group of four images, also simulate the next and
previous transition between slides in your JavaScript
<!DOCTYPE html>
<head>
<script language="Javascript">
MySlides=new Array('slide1.jpg','slide2.jpg','slide3.jpg','slide4.jpg')
i=0
function DisplaySlides(SlideNumber)
{
i=i+SlideNumber;
if (i>MySlides.length-1)
{
i=0;
}
if (i<0)
{
i=MySlides.length-1;
}
document.SlideID.src=MySlides[i];
}
</script>
</head>
<body>
<img src="slide1.jpg" name="SlideID" width="400" height="400" />
<br/><br/>
<input type="button" value="Back" onclick="DisplaySlides(-1)">
<input type="button" value="Forward" onclick="DisplaySlides(1)">
</body>
</html>
17. Write a suitable JavaScript to create a pull down menu.
<!DOCTYPE>
<html>
<head>
<title>Pull Down Menu</title>
<script language="Javascript">
function Display(Ch)
{
MyPage = Ch.options[Ch.selectedIndex].value
if (MyPage != "")
{
window.location = MyPage
}
}
</script>
</head>
<body onload="document.Form1.MyMenu.selectedIndex=0">
<form action="" name="Form1">
<select name="MyMenu" onchange="Display(this)">
<option>Books</option>
<option value="Fiction.html">Fiction</option>
<option value="NonFiction.html"> Non Fiction</option>
</select>
</form>
</body>
</html>
18. Create a slideshow with the group of four images, also simulate the next and
previous transition between slides in your JavaScript.
<!DOCTYPE html>
<head>
<script language="Javascript">
MySlides=new Array('slide1.jpg','slide2.jpg','slide3.jpg','slide4.jpg')
i=0
function DisplaySlides(SlideNumber)
{
i=i+SlideNumber;
if (i>MySlides.length-1)
{
i=0;
}
if (i<0)
{
i=MySlides.length-1;
}
document.SlideID.src=MySlides[i];
}
</script>
</head>
<body>
<img src="slide1.jpg" name="SlideID" width="400" height="400" />
<br/><br/>
<input type="button" value="Back" onclick="DisplaySlides(-1)">
<input type="button" value="Forward" onclick="DisplaySlides(1)">
</body>
</html>
19.Write a JavaScript that disables the right click button and displays the message
'Right click button is ‘disable'.
<!DOCTYPE html>
<html>
<head>
<title>Locking the Right Mouse Button</title>
<script language=JavaScript>
function RightClickDisable()
{
alert('Not allowed to right click');
return false;
}
function InternetExploreBrowser()
{
if (event.button==2)
{
RightClickDisable();
return false
}
}
document.oncontextmenu=new Function("RightClickDisable();return false")
</script>
</head>
<body>
<h1> This is a sample web page</h1>
<h4> Test disability of right click button by clicking right button</h4>
</body>
</html>