[Go to site: main page, start]

0% found this document useful (0 votes)
5 views14 pages

JavaScript Web Page Interactivity Guide

The document outlines several JavaScript programs including a web page with buttons that change background color and display messages, form validations for user input, string manipulation functions for counting vowels and checking palindromes, temperature conversion functions, and a program to calculate average marks and grades. Each section includes HTML and JavaScript code snippets demonstrating the functionality. The document serves as a guide for creating interactive web applications using JavaScript.

Uploaded by

alexlucifer445
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)
5 views14 pages

JavaScript Web Page Interactivity Guide

The document outlines several JavaScript programs including a web page with buttons that change background color and display messages, form validations for user input, string manipulation functions for counting vowels and checking palindromes, temperature conversion functions, and a program to calculate average marks and grades. Each section includes HTML and JavaScript code snippets demonstrating the functionality. The document serves as a guide for creating interactive web applications using JavaScript.

Uploaded by

alexlucifer445
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

JavaScript Program1

Create a web page in HTML having a white background and two Button Objects. Write code using
JavaScript such that when the mouse is placed over the first button object without clicking, the color
of the background of the page should change after every seconds. There should at least be 7 different
and visibly distinct background colors excluding the default color. When the second button object is
clicked, appropriate message should be displayed in Browsers status bar.

Create another web page using JavaScript where the background color changes automatically after
every seconds. This event must be triggered automatically after the page gets loaded in the browser.
There should at least be 7 different and visibly distinct background colors. When the page is
unloaded, the appropriate alert message should be displayed.

CODE

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body id="background">

<h1>Background Color is being changed every 1 seconds</h1>

<script>

var i = 0;

function change() {

var doc = [Link]("background");

var color = ["red", "blue", "brown", "green","yellow","pink","orange"];

[Link] = color[i];

i = i+1;

if(i==7){

[Link] = "white";

}
}

function click_btn() {

[Link] = "Background Color is being changed every 1 seconds";

</script>

<input type="button" name="b1" value="over here" 1000)">

<input type="submit" name="b2" value="click here" >

</body>

</html>
SOP 2:Create JavaScript program for the following form validations. Make use of HTML5 properties to
do the following validations :

1) Name, address, contact number and email are required fields of the form.

2) Address field should show the hint value which will disappear when field gets focus or key press
event.

3) Telephone number should be maximum 10 digit number only.

4) Email field should contain valid email address, @ should appear only once and not at the
beginning or at end. It must contain at least one dot(.).

5) Make use of pattern attribute for email to accept lowercase, uppercase alphabets, digits and
specified symbols.

Code

<!DOCTYPE html>

<html>

<head>

<title></title>

<script type="text/javascript">

function ValidateEmail(inputText)

var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

if([Link](mailformat))

[Link]();

return true;

else

{
alert("You have entered an invalid email address!");

[Link]();

return false;

} </script>

</head>

<body>

<h1>Information Form</h1>

<form action="" method="" name="f1">

<table>

<tr>

<td>Your Name</td>

<td><input type="text" name="t1" required></td>

</tr>

<tr>

<td>Address</td>

<td><textarea rows="5" cols="20" name="a1" required placeholder="Enter


Address"></textarea></td>

</tr>

<tr>

<td>Contact</td>

<td><input type="number" name="n1" maxlength="10" required></td>

</tr>

<tr>

<td>E-mail</td>

<td><input type="email" name="e1" required></td>


</tr>

<tr>

<td><input type="submit" name="submit" value="submit"


>

</tr>

</table>

</form>

</body>

</html>
SOP 4:

Create event driven JavaScript program for the following. Make use of appropriate variables,
JavaScript inbuilt string functions and control structures.

 To accept string from user and count number of vowels in the given string.

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<script type="text/javascript">

function getVowels() {

var vowelsCount = 0;

var str = [Link]("t1").value;

var string = [Link]();

for (var i = 0; i <= [Link] - 1; i++) {

if ([Link](i) == "a" || [Link](i) == "e" || [Link](i) == "i" || [Link](i) == "o" ||


[Link](i) == "u") {

vowelsCount += 1;

//[Link]("Total Vowels : "+vowelsCount);

[Link]('demo').innerHTML = "Total Vowels : "+vowelsCount;

return vowelsCount;
}

</script>

<tr>

<td><input type="text" id="t1"></td>

<td><input type="submit" name="submit" >

</tr>

<p id="demo"></p>

</body>

</html>

OutPut:
JavaScript Program4:

Create event driven JavaScript program for the following. Make use of appropriate variables,
JavaScript inbuilt string functions and control structures.

 To accept string from user and reverse the given string and check whether it is palindrome or
not.

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<script type="text/javascript">

function reverse_String() {

var str = [Link]('s1').value;

var final_str = str;

var split = [Link]("");

var reverse = [Link]();

var reverse_data = [Link]("");

[Link]("Reverse : "+reverse_data);

if (final_str==reverse_data) {

[Link]("<br>It is palindrome ");

else{

[Link]("<br>not palindrome ");

}
}

</script>

<input type="text" id="s1" placeholder="Enter a Striing">

<input type="submit" name="" >

</body>

</html>

OUTPUT:
SOP 5

Create event driven JavaScript program to convert temperature to and from Celsius, Fahrenheit.

Formula: c/5= (f-32)/9

[where c=Temperature in Celsius and f=Temperature in Fahrenheit.] Output format : 40 Celsius=104


Fahrenheit

45 Fahrenheit = 7.22222222 Celsius

<!DOCTYPE html>

<html>

<head>

<title></title>

<script type="text/javascript">

function get_Fahrenheit(){

var c = parseInt([Link]('c1').value);

var f;

//(f-32)/9 = c/5;

f = c/5*(9)+32;

[Link]("Fahrenheit : "+f);

function get_Celsius(){

var f = parseInt([Link]('f1').value);

var c;

//(f-32)/9 = c/5;

c = ((f-32)/9)*5;

[Link]("Celsius : "+c);

}
</script>

</head>

<body>

<input type="text" id="c1" placeholder="Temperature in Celsius">

<input type="submit" >

<br>

<input type="number" id="f1" placeholder="Temperature in Fahrenheit">

<input type="submit" >

</body>

</html>

OUTPUT:

Fahrenheit : 98.60000000000001
SOP 6:
Create JavaScript program which compute the average marks of students. Accept six subject marks of
student from user. Calculate average marks of student which is used to determine the corresponding
grades.

Range Grade

35 to 60 F

61 to 70 D

71 to 80 C

81 to 90 B

91 to 100 A

Code

<!DOCTYPE html>

<html>

<head>

<title>Enter Marks</title>

<script type="text/javascript">

function submit_marks() {

var sub1 = parseInt([Link]('s1').value);

var sub2 = parseInt([Link]('s2').value);

var sub3 = parseInt([Link]('s3').value);

var sub4 = parseInt([Link]('s4').value);

var sub5 = parseInt([Link]('s5').value);

var sub6 = parseInt([Link]('s6').value);

var total = sub1+sub2+sub3+sub4+sub5+sub6;

var per = total/6;


var grade;

if (per>=35 && per<=60) {

grade = 'F';

else if(per>=61 && per<=70){

grade = 'D';

else if(per>=71 && per<=80){

grade = 'C';

else if(per>=81 && per<=90){

grade = 'B';

else if(per>=91 && per<=100){

grade = 'A';

else{

grade = "Invalid or Failed";

[Link]("demo").innerHTML = "Your Total Marks : "+total+"<br>Your Percentage :


"+per+"<br>Your Grade : "+grade;

// [Link]("Your Total Marks : "+total);

// [Link]("<br>Your Percentage : "+per);

// [Link]("<br>Your Grade : "+grade);

</script>
</head>

<body>

<h1>Enter Students Marks</h1>

<input type="text" id="s1" placeholder="Enter English Marks"><br>

<input type="text" id="s2" placeholder="Enter IT Marks"><br>

<input type="text" id="s3" placeholder="Enter Physics Marks"><br>

<input type="text" id="s4" placeholder="Enter Chemistry Marks"><br>

<input type="text" id="s5" placeholder="Enter Maths Marks"><br>

<input type="text" id="s6" placeholder="Enter Biology Marks"><br>

<input type="submit" >

<div id="demo"></div>

</body>

</html>

Output

You might also like