[go: up one dir, main page]

0% found this document useful (0 votes)
40 views17 pages

PartB Programs Full

The document contains examples of JavaScript and PHP programs for performing various tasks: 1. A JavaScript program that validates university register numbers using regular expressions based on the course selected. 2. A JavaScript program that implements a login page and displays success or failure alerts based on the credentials. 3. A JavaScript program that changes the font style of a paragraph on mouseover and mouseout events. 4. A PHP program that accepts a number, calculates the sum of its digits recursively until the result is a single digit, and displays the output. 5. PHP programs to store student records in a database, display all records, search by register number and display the record, and update the address of

Uploaded by

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

PartB Programs Full

The document contains examples of JavaScript and PHP programs for performing various tasks: 1. A JavaScript program that validates university register numbers using regular expressions based on the course selected. 2. A JavaScript program that implements a login page and displays success or failure alerts based on the credentials. 3. A JavaScript program that changes the font style of a paragraph on mouseover and mouseout events. 4. A PHP program that accepts a number, calculates the sum of its digits recursively until the result is a single digit, and displays the output. 5. PHP programs to store student records in a database, display all records, search by register number and display the record, and update the address of

Uploaded by

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

Web Technology Lab Manual

PART-B

1. Write a JavaScript Program to Validate University Register Number using


Regular Expression.

<!DOCTYPE html>
<html>
<head>
<title>RegExp</title>
<script type="text/javascript">
function Check()
{
var crs=document.getElementById("course").value;
var regn=document.getElementById("regno").value;
var regex1 = /^[bcBC]{2}\d{6}$/;
var regex2 = /^[mM]\d{7}$/;
if(crs=="BCA")
{
if(regex1.test(regn))
{
alert("valid");
}
else
{
alert("Invalid");
}
}
if(crs=="BSc")
{
if(regex2.test(regn))
{
alert("valid");
}

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 1
Web Technology Lab Manual

else
{
alert("Invalid");
}
}
}
</script>
</head>
<body>
<h1>University of Mysore</h1>
<label>Select Course</label><br/>
<select id="course">
<option>--Select--</option>
<option>BCA</option>
<option>BSc</option>
</select><br/><br/>
<label>Enter Register Number</label><br/>
<input type="text" id="regno" name="regno" value=""><br/><br/>
<button id="submit" onclick="Check()">Validate</button>
</body>
</html>
Output:

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 2
Web Technology Lab Manual

2. Write a JavaScript Program to Implement login page (if login credentials are
correct, display ‘login successful’ or display ‘login unsuccessful’ using alert)

<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<script type="text/javascript">
function Check()
{
var un=document.getElementById("uname").value;
var ps=document.getElementById("pass").value;
if((un=="admin") && (ps=="ram"))
{
alert("Login Successfull");

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 3
Web Technology Lab Manual

}
else
{
alert("Login Unsuccessfull");
}
}
</script>
</head>
<body>
<h1>Login Here</h1>
<label>UserName</label><br/>
<input type="text" id="uname" name="uname" value=""><br/>
<label>Password</label><br/>
<input type="password" id="pass" name="pass" value=""><br/><br/>
<button id="login" onclick="Check()">SignIn</button>
</body>
</html>
Output:

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 4
Web Technology Lab Manual

3. Develop and demonstrate a HTML page containing JavaScript function to


change the font style of a paragraph on mouse over and on mouse out events.

<!DOCTYPE html>
<html>
<head>
<title>font style</title>
<script type="text/javascript">
function Change()
{
para.style.fontSize = "14pt";
para.style.fontFamily = "Comic Sans MS";
para.style.color = "green";
}
function Changeback()
{
para.style.fontSize = "15pt";
para.style.fontFamily = "Times New Roman";
para.style.color = "red";
}
</script>
</head>
<body>
<h1>Paragraph Here</h1>
<p id="para" onmouseover="Change()" onmouseout="Changeback()">Develop and
demonstrate a HTML page containing JavaScript function to
change the font style of a paragraph on mouse over and on mouse out events.</p>
</body>
</html>
Output:

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 5
Web Technology Lab Manual

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 6
Web Technology Lab Manual

4. Write a PHP Program to Accept the number and Compute sum of its Digits until
the result digit becomes a single Digit.

B4.php

<html>
<head>
<title>PHP Program</title>
</head>
<body>
<h1>Sum of its Digits </h1>
<form method="POST" action="B4.php">
<label>Enter a Number:</label>
<input type="text" name="numb">
<input type="submit" value="Result" name="submit">
</form>
<?php
function digSum( $n)
{
$sum = 0;
while($n > 0 || $sum > 9)
{
if($n == 0)
{
$n = $sum;
$sum = 0;
}
$sum += $n % 10;
$n = (int)$n / 10;
}
return $sum;
}

if(isset($_POST['submit']))
{
$n = $_POST['numb'];
echo digSum($n);
}
?>
</body>
</html>

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 7
Web Technology Lab Manual

Output:

5. Write a PHP Program to store Student records into a database and display all
the records.

Student.html

<?xml version="1.0" encoding="utf-8" ?>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> SMS </title>
</head>
<body bgcolor="pink">
<center><h4>Fill the given details</h4></center>
<form action="add_student.php" method="post">
<table border="0" cellspacing="5" cellpadding="5" align="center">
<tr>
<td><b>Roll No:</b></td>
<td><input type="text" name="roll_no" required></td>
</tr>
<tr>
<td><b>Name:</b></td>
<td><input type="text" name="name" required></td>
</tr>
<tr>
<td><b>Father's Name:</b></td>
<td><input type="text" name="father_name" required></td>
</tr>

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 8
Web Technology Lab Manual

<tr>
<td><b>Class:</b></td>
<td><input type="text" name="class" required></td>
</tr>
<tr><td><b>Mobile:</b></td>
<td><input type="text" name="mobile" required></td>
</tr>
<tr>
<td><b>Email:</b></td>
<td><input type="text" name="email" required></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type="password" name="password" required></td>
</tr>
<tr>
<td><b>Address:</b></td>
<td><textarea rows="3" cols="40" name="address"></textarea></td>
</tr>
<tr>
<td></td>
<td><br><input type="submit" name="add" value="Add Student"></td>
</tr>
</table>
</form>
</body>
</html>

add_student.php

<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"sms");
$query = "insert into students
values('',$_POST[roll_no],'$_POST[name]','$_POST[father_name]','$_POST[class]','$_POST[mobile]','$_P
OST[email]','$_POST[password]','$_POST[address]')";
$query_run = mysqli_query($connection,$query);
?>
<script type="text/javascript">
alert("Student added successfully.");
</script>

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 9
Web Technology Lab Manual

Database: sms
Table :students

Display.php

<!DOCTYPE html>
<html>
<head>
<title> SMS </title>
</head>
<body bgcolor="lightgray">
<?php

$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"sms");
?>
<center>
<h1>Student Details</h1>
<table border="2" cellspacing="5" cellpadding="5">
<tr>
<th><b>Roll No</b></th>
<th><b>Name</b></th>
<th><b>Father's Name</b></th>
<th><b>Class</b></th>
<th><b>Mobile</b></th>
<th><b>Email</b></th>
<th><b>Password</b></th>
<th><b>Remark</b></th>
</tr>

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 10
Web Technology Lab Manual

<?php
$query = "select * from students";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run))
{
?>

<tr>
<td><?php echo $row['roll_no']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['father_name']?></td>
<td><?php echo $row['class']?></td>
<td><?php echo $row['mobile']?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['password']?></td>
<td><?php echo $row['address']?></td>
</tr>
<?php
}

?>

</table>
</center>
</body>
</html>

Output:

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 11
Web Technology Lab Manual

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 12
Web Technology Lab Manual

6. Write a PHP Program to Search Student information based on Register


_Number and display it in a Table.

Search.php

<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Search</title>
</head>
<body bgcolor="pink">
<center>
<form action="" method="post">
<br/>
<br/>
&nbsp;&nbsp;<b>Enter Roll No:</b>&nbsp;&nbsp; <input type="text" name="roll_no">
<input type="submit" name="search_by_roll_no" value="Search">
</form><br><br>
</center>
<?php
if(isset($_POST['search_by_roll_no']))
{
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"sms");
?>
<center>
<h1>Student Details</h1>
<table border="2" cellspacing="5" cellpadding="5">
<tr>
<th><b>Roll No</b></th>
<th><b>Name</b></th>
<th><b>Father's Name</b></th>
<th><b>Class</b></th>
<th><b>Mobile</b></th>
<th><b>Email</b></th>
<th><b>Password</b></th>
<th><b>Address</b></th>
</tr>
JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 13
Web Technology Lab Manual

<?php
$query = "select * from students where roll_no = '$_POST[roll_no]'";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run))
{
?>

<tr>
<td><?php echo $row['roll_no']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['father_name']?></td>
<td><?php echo $row['class']?></td>
<td><?php echo $row['mobile']?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['password']?></td>
<td><?php echo $row['address']?></td>
</tr>
<?php
}

?>

</table>
</center>
<?php
}
?>
</body>
</html>

Output:

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 14
Web Technology Lab Manual

7. Write a PHP Program to Search Student information based on Register_Number


and update the Address of that Student.

Edit.php

<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Search</title>
</head>
<body bgcolor="pink">
<center>
<form action="" method="post">
<br/>
<br/>
&nbsp;&nbsp;<b>Enter Roll No:</b>&nbsp;&nbsp; <input type="text" name="roll_no">
<input type="submit" name="search_by_roll_no" value="Search">
</form><br><br>
</center>
<?php
if(isset($_POST['search_by_roll_no']))
{

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 15
Web Technology Lab Manual

$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"sms");
$query = "select * from students where roll_no = $_POST[roll_no]";
$query_run = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($query_run))
{
?>
<form action="update.php" method="post">
<table>
<tr>
<td>
<b>Roll No:</b>
</td>
<td>
<input type="text" name="roll_no" value="<?php echo $row['roll_no']?>" readonly>
</td>
</tr>
<tr>
<td>
<b>Address:</b>
</td>
<td>
<textarea rows="3" cols="40" name="address"><?php echo $row['address']?></textarea>
</td>
</tr><br>
<tr>
<td></td>
<td>
<input type="submit" name="edit" value="Save">
</td>
</tr>
</table>
</form>
<?php
}
}
?>
</body>
</html>

Update.php

<?php
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,"sms");
$query = "update students set address='$_POST[address]' where roll_no =
$_POST[roll_no]";
JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 16
Web Technology Lab Manual

$query_run = mysqli_query($connection,$query);
?>
<script type="text/javascript">
alert("Details edited successfully.");

</script>

Output:

JAYARAM N, Asst. Professor, Dept. of Computer Science, NIE FGC, Mysore Page 17

You might also like