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

Web Programscode&Output

The document contains code for several web programs demonstrating different JavaScript and PHP concepts: 1. The first program shows how to handle mouseover, click, and focus events using JavaScript. 2. The second program defines a simple JavaScript object. 3. Additional programs demonstrate number methods, jQuery effects, a factorial program in PHP, and student registration forms using PHP and sessions.

Uploaded by

Tamanna
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Web Programscode&Output

The document contains code for several web programs demonstrating different JavaScript and PHP concepts: 1. The first program shows how to handle mouseover, click, and focus events using JavaScript. 2. The second program defines a simple JavaScript object. 3. Additional programs demonstrate number methods, jQuery effects, a factorial program in PHP, and student registration forms using PHP and sessions.

Uploaded by

Tamanna
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Web programs

Program 1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>events in js</title>
</head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function mouseoverevent()
{
alert("This is JavaTpoint");
}
//-->
</script>
<p onmouseover="mouseoverevent()"> Keep cursor over me</p>
<script>

function clickevent()
{
document.write("This is JavaTpoint");
}
//-->
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?">
</form>
<h2> Enter something here</h2>
<input type="text" id="input1" onfocus="focusevent()"/>
<script>
<!--
function focusevent()
{
document.getElementById("input1").style.background="
aqua";
}
//-->
</script>
<body onload="window.alert('Page successfully loaded');">
<script>
<!--
document.write("The page is loaded successfully");
//-->
</script>
</body>
</html>

Output
Program 2a and 2b
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>objects in js</title>
</head>
<body>
<script>
// javascript code demonstrating a simple object
let school = {
name: 'Vivekananda School',
location : 'Delhi',
established : '1971',
displayInfo : function(){
console.log(`${school.name} was established
in ${school.established} at ${school.location}`);
}
}
school.displayInfo();
</script>
</body>
</html>

<html>
<body>

<h1>JavaScript Number Methods</h1>

<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>

<script>
let x = 123;
document.getElementById("demo").innerHTML =
x.toString() + "<br>" +
(123).toString() + "<br>" +
(100 + 23).toString();
</script>

<script>
let y = 9.656;
document.getElementById("demo1").innerHTML =
y.toExponential() + "<br>" +
y.toExponential(2) + "<br>" +
y.toExponential(4) + "<br>" +
y.toExponential(6);
</script>
<script>
let z = 9.656;
document.getElementById("demo2").innerHTML =
z.toFixed(0) + "<br>" +
z.toFixed(2) + "<br>" +
z.toFixed(4) + "<br>" +
z.toFixed(6);
</script>

<script>
let a = 9.656;
document.getElementById("demo3").innerHTML =
a.toPrecision() + "<br>" +
a.toPrecision(2) + "<br>" +
a.toPrecision(4) + "<br>" +
a.toPrecision(6);
</script>
<script>
let b = 150;

document.getElementById("demo4").innerHTML =
b.valueOf() + "<br>" +
(150).valueOf() + "<br>" +
(100 + 50).valueOf();
</script>

</body>
</html>

Output
Program 3
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeToggle();
$("#div2").fadeToggle("slow");
$("#div3").fadeToggle(3000);
});
});
</script>
</head>
<body>

<p>Demonstrate fadeToggle() with different speed parameters.</p>

<button>Click to fade in/out boxes</button><br><br>

<div id="div1" style="width:80px;height:80px;background-color:red;"></div>


<br>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div>
<br>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>

</body>
</html>

Output
Program 4
<!DOCTYPE html>
<html>
<body>

<?php
$n = 10;
$f = 1;
for ($i=$n; $i>=1; $i--)
{
$f = $f * $i;
}
echo "$n! = $f";
?>

</body>
</html>

Output:
Program 5

Program 6
Program 7
Create simple student registration form and display student information using PHP

phpform.php

<!-- STUDENT REGISTRATION FORM -->


<html>
<head>
<title>Document</title>
</head>
<body>
<h3>Student Registration Form</h3>
<formaction="registration.php"method="POST">
<table>
<tr>
<td><label>First Name: </label></td>
<td><inputtype="text"name="firstname"></td>
</tr>
<tr>
<td><label>Last Name: </label></td>
<td><inputtype="text"name="lastname"></td>
</tr>
<tr>
<td><label>Father Name: </label></td>
<td><inputtype="text"name="fathername"></td>
</tr>
<tr>
<td><label>Date of Birth: </label></td>
<td><inputtype="date"name="dob"></td>
</tr>
<tr>
<td><label>Email: </label></td>
<td><inputtype="email"name="email"></td>
</tr>
<tr>
<td><label>Phone Number: </label></td>
<td><inputtype="text"name="phone"></td>
</tr>
<tr>
<td><label>Gender: </label></td>
<td><inputtype="radio"name="gender"value="male"checked>Male
<inputtype="radio"name="gender"value="female">Female</td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><textareaname="address"rows="4"cols="20"></textarea></td>
</tr>
<tr>
<td><label>Course enrolled: <label></td>
<td><selectname="course"id="course">
<optionvalue="0"selected>Select</option>
<optionvalue="BCA">BCA</option>
<optionvalue="BBA">BBA</option>
<optionvalue="MCA">MCA</option>
<optionvalue="BCA-CTIS">BCA-CTIS</option>
</select></td>
</tr>
<tr>
<td><inputtype="submit" value="submit">
<inputtype="reset"value="reset"</td>
</tr>
</table>
</form>
</body>
</html>

registration.php
<!-- STUDENT INFORMATION -->
<html>
<head>
<title>Document</title>
</head>
<body>
<h3>Student Information</h3>
<table>
<tr>
<td><b>Student Name:</b></td>
<td><?php echo $_POST["firstname"]." ".$_POST["lastname"];?></td>
</tr>
<tr>
<td><b>Fahter Name:</b></td>
<td><?php echo $_POST["fathername"];?></td>
</tr>
<tr>
<td><b>Date of Birth:</b></td>
<td><?php echo $_POST["dob"];?></td>
</tr>
<tr>
<td><b>Email:</b></td>
<td><?php echo $_POST["email"]; ?></td>
</tr>
<tr>
<td><b>Phone Number:</b></td>
<td><?php echo $_POST["phone"]; ?></td>
</tr>
<tr>
<td><b>Gender: </b></td>
<td><?php echo $_POST["gender"]; ?></td>
</tr>
<tr>
<td><b>Address:</b></td>
<td><?php echo $_POST["address"]; ?></td>
</tr>
<tr>
<td><b>Course Enrolled:</b></td>
<td><?php echo $_POST["course"]; ?></td>
</tr>

<table>
</body>
</html>
Program 8
Program to demonstrate use of session in PHP

//session_create.php

<html>
<body>
<?php
session_start();
$_SESSION["username"]="Mention-Yourname";
$_SESSION["password"]="p@ssword";
echo "You have saved you session successfully";
?>
<br><ahref="session_data.php">Get Data using session</a>
<br><ahref="session_close.php">Destroy Session</a>
</body>
</html>

// session_data.php

<html>
<body>
<?php
session_start();
if(isset($_SESSION['username'])){
echo "Hello! ".$_SESSION["username"];
echo "<br>";
echo "Your Password: ".$_SESSION["password"];
}
else{
echo "Please login";
}
?>
</body>
</html>

//session_close.php
<?php
session_start();
session_unset();
session_destroy();
echo "<br>You've been logged out[session Out].";
?>
Program 9
Program no. 9

//cookies.php
<?php
echo "Demonstrating Cookies";
//Syntax :setcookie(name, value, expire, path, domain, security);
setcookie("skills", "php", time()+1, "/"); //expires in 1 sec
?>
<html>
<body>
<?php
//checking whether cookie is set or not
if(isset($_COOKIE["skills"]))
{
echo "<br>you are interested in ".$_COOKIE["skills"];
}
else
{
echo "<br>Set the cookie....";
}
?>
</body>
</html>
Program 10
Program no. 10
//database.php

<?php
//creating database using MySQl in php
//To connect to the database
$servername = "localhost";
$username = "root";
$password = "";

$connection = mysqli_connect($servername, $username, $password);


if(!$connection){
die("Failed to connect: ".mysqli_connect_error());

}
else{
echo "Successfully connected !<br>";
}

// to create the database


$sql_db = "CREATEDATABASE DB3"; //DB3 is the name of database
$db_result = mysqli_query($connection, $sql_db);
// returns true if created successfully else false if already exists or not
created

if($db_result){
echo "Database created successfully";
}
else{
echo "Error occured: ".mysqli_error($connection);
}
?>

You might also like