WT Practical File
WT Practical File
INDEX
PRACTICAL:1
AIM: Create registration form in HTML.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Registration form Practical 1</title>
</head>
<body>
<h2>Registration form</h2>
<form action="#" method="post">
<table>
<tr>
<td>Enrollment No*: </td>
<td>
<input type="text" name="er_no" required>
</td>
</tr>
<tr>
<td>Name: </td>
<td>
<input name="name" type="text">
</td>
</tr>
<tr>
<td>Year: </td>
<td>
<input name="year" type="text" >
</td>
</tr>
<tr>
<td>Branch: </td>
<td>
<select name="branch" >
<option value="it">Information Technology</option>
<option value="cp">Computer Engineering</option>
<option value="me">Mechanical Engineering</option>
<option value="auto">Automobiles</option>
<option value="ec">Electronics And Communication</option>
<option value="ee">Electrical Engineering</option>
<option value="fpt">Food Processing Technology</option>
</select>
</td>
</tr>
<tr>
<td>Email*: </td>
<td>
<input name="email" type="text" >
</td>
</tr>
<tr>
<td>Mobile*: </td>
<td>
<input name="mobile" type="number">
</td>
</tr>
<tr>
<td>Password: </td>
<td>
<input name="password" type="password" required>
</td>
</tr>
<tr>
<td>
<br><input name="Submit" type="Submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
PRACTICAL: 2
AIM: Write html Page which shows the use of Inline, Internal and External CSS.
Code:
(HTML)
<!DOCTYPE html>
<html>
<head>
<title>Types Of CSS Practical 2</title>
<style>
p{
color:grey;
}
</style>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
<p style="color:orange">This is Inline CSS.<br><br></p>
<p style="color:orange">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Nihil dolorem, quasi saepe error odit labore, fuga eligendi nesciunt voluptatibus reiciendis natus.
<br>Ut voluptatem fugit, nesciunt itaque totam debitis voluptatibus beatae.
</p>
<p><br>This is Internal CSS.<br><br></p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Nihil dolorem, quasi saepe error odit labore, fuga eligendi nesciunt voluptatibus reiciendis natus.
<br>Ut voluptatem fugit, nesciunt itaque totam debitis voluptatibus beatae.
</p>
<p id="ex1"><br>This is External CSS.<br><br></p>
<p id="ex1">
Lorem ipsum dolor sit amet consectetur adipisicing elit.
Nihil dolorem, quasi saepe error odit labore, fuga eligendi nesciunt voluptatibus reiciendis natus.
<br>Ut voluptatem fugit, nesciunt itaque totam debitis voluptatibus beatae.
</p>
</body>
</html>
(CSS/Styles.css)
#ex1{
color:green;
}
Output:
PRACTICAL: 3
AIM: Write code Which shows the Use of Javascript Switch Case and Function for the same.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Javascript Switch & Function Practical 3</title>
</head>
<body>
<div>
Enter 1<sup>st</sup> No.: <input type="number" id="num1"><br>
Enter 2<sup>nd</sup> No.: <input type="number" id="num2"><br>
</div>
<p>
Enter:<br>
1. for Addition<br>
2. for Subtraction<br>
3. for Multiplication<br>
4. for Division<br>
5. for Modulo<br>
</p>
<div>
<input type="number" id="op" >
</div>
<br><input type="button" value="Calculate" onclick="check()">
<div id="result">
</div>
<script>
function check(){
num1 = Number(document.getElementById("num1").value);
num2 = Number(document.getElementById("num2").value);
op = document.getElementById("op").value;
console.log(num1);
console.log(num2);
console.log(op);
switch(op){
case '1':
sum(num1,num2);
break;
case '2':
sub(num1,num2);
break;
case '3':
mul(num1,num2);
break;
case '4':
division(num1,num2);
break;
case '5':
mod(num1,num2);
break;
default:
msg();
break;
}
}
function sum(x,y){
z = x+y;
document.getElementById("result").innerHTML="<br>Addition of " + x + " and " + y + " is: " + z;
}
function sub(x,y){
z = x-y;
document.getElementById("result").innerHTML="<br>Subtraction of " + x + " and " + y + " is: " + z;
}
function mul(x,y){
z = x*y;
document.getElementById("result").innerHTML="<br>Multiplication of " + x + " and " + y + " is: " + z;
}
function division(x,y){
z = x/y;
document.getElementById("result").innerHTML="<br>Division of " + x + " and " + y + " is: " + z;
}
function mod(x,y){
z = x%y;
document.getElementById("result").innerHTML="<br>Modulo of " + x + " and " + y + " is: " + z;
}
function msg(){
document.getElementById("result").innerHTML="<br>Please Eneter Valid Inputs";
}
</script>
</body>
</html>
Output:
PRACTICAL: 4
AIM: Create HTML Form which includes validation using JavaScript.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Form Validation Practical 5</title>
<script src="mobilejs.js"></script>
</head>
<body>
<h2>Registration form</h2>
<form method="post" action="form.html">
<table>
<tr>
<td>Enrollment No*: </td>
<td>
<input type="text" id="er_no" required>
</td>
</tr>
<tr>
<td>Name: </td>
<td>
<input id="name" type="text">
</td>
</tr>
<tr>
<td>Email*: </td>
<td>
<input id="email" type="text" required>
</td>
</tr>
<tr>
<td>Mobile*: </td>
<td>
<input id="mobile" type="number" required>
</td>
</tr>
<tr>
<td>Password: </td>
<td>
<input id="password" type="password" required>
</td>
</tr>
<tr>
<td>
<br><input id="Submit" type="Submit" value="Submit" onclick="validate()">
</td>
</tr>
</table>
</form>
<script>
function validate(){
var x = document.getElementById("mobile").value;
var d = /\d/;
if(x.length<10){
alert("Mobile Number Must Be 10 Digits Number!");
}
if(!d.test(x)){
alert("Please enter numeric value!")
}
}
</script>
</body>
</html>
Output:
PRACTICAL: 5
AIM: Write a javascript code to show the concept of DOM.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Concept Of DOM Practical 5</title>
</head>
<body>
<div>
Name: <input type="text" id="name" onkeyup="printmsg()">
</div>
<div id="msg"></div>
<script>
function printmsg(){
name = document.getElementById("name").value;
document.getElementById("msg").innerHTML = "<br><br>Hey "+ name +"!<br>Nice to meet you!";
}
</script>
</body>
</html>
Output:
PRACTICAL: 6
AIM: Javascript with Cookies.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Cookies Practical 6</title>
<script type = "text/javascript">
function WriteCookie() {
name = document.getElementById("name").value;
cookievalue = document.getElementById("no").value + ";";
document.cookie = name+"=" + cookievalue;
document.getElementById("msg").innerHTML = "Cookies Name: " +name+ " Content= " + cookievalue ;
}
</script>
</head>
<body>
Enter name: <input type = "text" id="name">
<br><br>Er_No: <input type="number" id="no">
<br><br><input type = "button" value = "Set Cookie" onclick = "WriteCookie();"/>
<div id="msg"></div>
</body>
</html>
Output:
PRACTICAL: 7
AIM: Create Student.xml file which shows the details of student.
Code:
<?xml version="1.0"?>
<!DOCTYPE Student_Data [
<!ELEMENT Music_Album (Er_No,Name,Dept,Year,Collage,University,Joininng_Year,Passing_Year)>
<!ELEMENT Er_No (Int)>
<!ELEMENT Name (String)>
<!ELEMENT Dept (String)>
<!ELEMENT Year (Int)>
<!ELEMENT Collage (String)>
<!ELEMENT University (String)>
<!ELEMENT Joininng_Year (Int)>
<!ELEMENT Passing_Year (Int)>
]>
<Student_Data>
<Er_No> 170010116050 </Er_No>
<Name> Neel Shah </Name>
<Dept> Information Technology </Dept>
<Year> 3 </Year>
<Collage> ADIT </Collage>
<University> GTU </University>
<Joininng_Year> 2017 </Joininng_Year>
<Passing_Year> 2021 </Passing_Year>
</Student_Data>
Output:
PRACTICAL: 8
AIM: Write Examples which shows the use of XML DTD and XML Schema.
Code:
(XML DTD)(Student.xml)
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<Student_Data>
<Er_No> 170010116050 </Er_No>
<Name> Neel Shah </Name>
<Dept> Information Technology </Dept>
<Year> 3 </Year>
<Collage> ADIT </Collage>
<University> GTU </University>
<Joininng_Year> 2017 </Joininng_Year>
<Passing_Year> 2021 </Passing_Year>
</Student_Data>
(XML DTD)(Note.dtd)
<!DOCTYPE Student_Data [
<!ELEMENT Student_Data (Er_No,Name,Dept,Year,Collage,University,Joininng_Year,Passing_Year)>
<!ELEMENT Er_No (Int)>
<!ELEMENT Name (String)>
<!ELEMENT Dept (String)>
<!ELEMENT Year (Int)>
<!ELEMENT Collage (String)>
<!ELEMENT University (String)>
<!ELEMENT Joininng_Year (Int)>
<!ELEMENT Passing_Year (Int)>
]>
Output:
(XML DTD)(Student_Schema.xml)
<?xml version="1.0"?>
<Student_Data xmlns="https://www.adit.ac.in" xmlns:xsi="http://www.adit.ac.in" xsi:schemaLocation="schema.xsd ">
<Er_No> 170010116050 </Er_No>
<Name> Neel Shah </Name>
<Dept> Information Technology </Dept>
<Year> 3 </Year>
<Collage> ADIT </Collage>
<University> GTU </University>
<Joininng_Year> 2017 </Joininng_Year>
<Passing_Year> 2021 </Passing_Year>
</Student_Data>
(XML DTD)(schema.xsd)
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.adit.ac.in"
targetNamespace="https://www.adit.ac.in"
xmlns="https://www.adit.ac.in"
elementFormDefault="qualified">
<xs:element name="Student_Data">
<xs:complexType>
<xs:sequence>
<xs:element name="Er_No" type="xs:integer"/>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Dept" type="xs:string"/>
<xs:element name="Year" type="xs:integer"/>
<xs:element name="Collage" type="xs:string"/>
<xs:element name="University" type="xs:string"/>
<xs:element name="Joining_Year" type="xs:integer"/>
<xs:element name="Passing_Year" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Output:
(Student_Data_Schema.xml)
(schema.xsd)
PRACTICAL: 09
AIM: Design a Form in PHP with validation.
Code:
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["website"])) {
$website = "";
} else {
$website = test_input($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",
$website)) {
$websiteErr = "Invalid URL";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
Output:
PRACTICAL: 10
AIM: Write php code which shows the use of MySQL.
Code:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "kevin";
$password = "";
$dbname = "mydb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM mytable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th></tr>";
while($row = $result->fetch_assoc()) {
Output: