Professional Documents
Culture Documents
Table of Contents
5. JSON
Aim:
To write a HTML code for designing a curriculum vitae with necessary tags.
Tags used:
<html> -it defines the whole document. It has a start tag <html> and an end tag
</html>.
<body> -it defines the document body. It has a start tag <body> and an end tag
</body>.
<table > -An HTML table is defined with the <table> tag.
<ul> -HTML lists are defined with the <ul> (unordered/bullet list) .
<h1> - it defines a heading. It has a start tag <h1> and an end tag </h1>.
<marquee> -it is used for scrolling piece of text or image displayed either
horizontally across or vertically down your web page.
Code:
1) Edu.html
<html>
<body>
<table style="width:10%" border=2>
<tr>
<th>Qualification</th>
<th>Institution</th>
<th>Percentage</th>
</tr>
<tr>
<td>10th</td>
<td>St. Josephs</td>
<td>90</td>
</tr>
<tr>
<td>12th/td>
<td>mk gandhi</td>
<td>94</td>
</tr>
</table>
</body>
</html>
2) Personal.html
<html>
<head>
<title> Personal Information </title>
</head>
<body>
<ul>
<li> Name : Sathyabama</li>
<li> email: sathyabama@gmail.com </li>
</ul>
<ol> <b> Hobbies </b>
<li> Listening Music</li>
<li> watching TV </li>
</ol>
</body>
</html>
3) f1.html
<html>
<head>
<title> f1.html </title>
</head>
<body>
<h2> Curriculum Vitae </h2>
<a href="personal.html" target="main"> Personal Information<br></a>
<a href="edu.html" target="main"> Educational Qualification<br> </a>
</body>
</html>
4) f2.html
<html>
<head>
<title> f2.html </title>
</head>
<body>
<h1> <marquee> < My Details > </marquee> </h1>
</body>
</html>
5) Main.html
<html>
<head>
<title> Frame tag </title>
</head>
<head>
<frameset cols="20,80">
<frame src="f1.html">
<frame src="f2.html" name="main">
</frameset>
</head>
</html>
Output:
Result:
Aim :
Tags Used:
<html> - Defines a HTML document
<head> - Defines information about the document
<title> - Defines a title about the document
<p> - Defines a paragraph
<div> - Defines a division or section in a HTML document
<input> - Specifies an input field where the user can enter data
JQuery:
- JQuery is a Javascript Library
$ - Element selector which selects the elements based on the element
name
#id - Uses the ‘id’ attribute of a HTML tag to find the specific element
Click - Mouse event
Code:
<html>
<head>
<title>Client Side Validation using JQuery</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$('#psw').click('input',function() {
var error = 0;
var name = $('#name').val();
if (name == '') {
error = 1;
alert('Name cannot be empty');
}
if(error){
return false;
}else{
return true;
}
});
$('#mail').click('input',function() {
var error = 0;
var psw = $('#psw').val();
if (psw.length<=5) {
error = 1;
alert('Password should be atleast 6 in length');
}
if(error){
return false;
}else{
return true;
}
});
$('#contact_submit').click('input',function() {
var error = 0;
var mail = $('#mail').val();
var re = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-
]+)*$/;
var ismail=re.test(mail);
if (ismail) {alert(" Registration Successful");
}
else{
alert("invalid email");
return true;
}
});
});
</script>
</head>
<body>
<p> <label>REGISTRATION FORM</label>
<p> <label> Name: </label>
<input type='text' name='test_field' id='name' />
<p> <label> Password: </label>
<input type='text' name='password' id='psw' />
<p> <label> E-mail: </label>
<input type='text' name='E-mail' id='mail' />
<div id='contact_submit'>
<p><button type='submit'>Submit</button>
</div>
</body>
</html>
Output
Result:
Thus the client side form validation using JQuery has been executed successfully.
Ex. No. 3
SEMANTIC ELEMENTS IN HTML
Date:
Aim:
To write a HTML code for designing a web page using semantic elements.
Explanation:
Tags used:
HTML5 offers new semantic elements to define different parts of a web page:
<aside> - Defines some content aside from the content it is placed in.
<html>
<head>
<title>HTML5</title>
<style>
body {
font-family: Verdana,sans-serif;
font-size: 0.9em;
header, footer {
padding: 10px;
color: white;
background-color: black;
color:green;
section {
margin: 5px;
padding: 10px;
background-color: lightgrey;
color:blue;
article {
margin: 5px;
padding: 10px;
background-color: white;
color:red;
nav ul {
padding: 0;
</style>
</head>
<body>
<header>
<h1>Times Now</h1>
</header>
<nav>
<a href="news.html">ChennaiNow</a> |
<a href="sports.html">Sports</a> |
<a href="weather.html">Weather</a> |
</nav>
<section>
<h2>News Section</h2>
<article>
<h2>India</h2>
</article>
<figure>
</figure>
<article>
<h2>News Article</h2>
<p>The UN report titled The World Population Prospects 2019: Highlights, the
world's population is getting older due to increasing life expectancy and falling
fertility levels.</p>
</article>
</section>
<footer>
</footer>
</body>
</html>
Output :
Result:
Thus a web page has been designed using semantic elements successfully.
Ex. No. 4
PHP AND MYSQL
Date:
Aim:
To design an application to fetch information from a Mysql database and
display the records in a web page using PHP.
1. Create the database and then create table student in mysql with field
sname,regno,m1,m2
Goto xampp control panel of xampp and start mysql and apache.
(i) Go to C:
3. create a folder in htdocs of xampp and store the above two files.
Procedure to Run:
1.Type http://localhost/folder name in explorer
Content of folder will be displayed
2. Click the html file and enter the data.
HTML CODE
<!DOCTYPE>
<html>
<head>
<script>
function myFunction() {
var m1 = Number(document.getElementById("m1").value);
var m2 = Number(document.getElementById("m2").value);
var avg =(m1+m2)/2;
document.getElementById("avg").value= avg;
}
</script>
</head>
<title>Student Details</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div id="student1"><h3>Student Details</h3>
<form method="POST" action="http://localhost/dbcon/connect.php">
Rollno <br> <input id="no" name="no"></br></br>
Name <br> <input id="name" name="name"></br></br>
Mark1 <br> <input id="m1" name="m1"></br></br>
Mark2 <br> <input id="m2" name="m2"></br></br>
Average <br> <input id="avg" name="avg" onclick="myFunction()">
</br></br>
<input type="submit" id="submit" value="Submit">
<input type="reset" id="reset" value="Reset">
</form>
</div>
</body>
</html>
CSS CODE
#body-color
{
background-color:"#E6E6FA";
}
#student1
{
margin-top:150px;
margin-bottom:150px;
margin-right:150px;
margin-left:150px;
border:3px solid #a1a1a1;
padding:9px 35px;
background:#E6E6FA;
width:250px;
border-radius:20px;
box-shadow: 7px 7px 6px;
}
#submit{
border-radius:10px;
width:100px;
height:40px;
background:#EEAEAE;
font-weight:bold;
font-size:20px
}
#reset{
border-radius:10px;
width:100px;
height:40px;
background:#EEAEAE;
font-weight:bold;
font-size:20px
}
PHP CODE
<?php
$servername="localhost";
$user="root";
$password="";
$dbname = "stud";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$no= $_POST["no"];
$name = $_POST["name"];
$m1 = $_POST["m1"];
$m2 = $_POST["m2"];
$avg =($m1+$m2)/2;
}
Output:
Result:
Thus an application to fetch information from a Mysql database was created and
the records were displayed in a web page using PHP successfully.
Ex. No. 5
JSON
Date:
Aim:
To access a JSON text and display it in the web page.
Explanation:
XAMPP
htdocs:
Steps:
Code:
<html>
<head>
<meta content="text/html; charset=utf-8">
<title>AJAX JSON by Javatpoint</title>
<script type="application/javascript">
function load()
{
var url = "http://date.jsontest.com/"; //use any url that have json data
var request;
if(window.XMLHttpRequest){
request=new XMLHttpRequest(); //for Chrome, mozilla etc
}
else if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP"); //for IE only
}
request.onreadystatechange = function(){
if (request.readyState == 4 )
{
var jsonObj = JSON.parse(request.responseText); //JSON.parse() returns
JSON object
document.getElementById("date").innerHTML = jsonObj.date;
document.getElementById("time").innerHTML = jsonObj.time;
document.getElementById("seconds").innerHTML= jsonObj.milliseconds_since_epoch;
}
}
request.open("GET", url, true);
request.send();
}
</script>
</head>
<body>
Date : <span id="date"></span><br/>
Time : <span id="time"></span><br/>
Seconds : <span id="seconds"></span><br/>
<br/>
<br/>
<button type="button" onclick="load()">VIEW </button>
</body>
</html>
OUTPUT:
Result:
Thus the content from JSON text file is retrieved and printed in the web page
successfully.
Ex. No. 6
JSON and PHP
Date:
Aim:
To create a record, store in JSON text and print in the web page using PHP.
Explanation:
XAMPP
htdocs:
PHP:
PHP is a server scripting language, and a powerful tool for making dynamic
and interactive Web pages.
PHP is a widely-used, free, and efficient alternative to competitors such as
Microsoft's ASP.
JSON: JavaScript Object Notation.JSON is a syntax for storing and
exchanging data.JSON is text, written with JavaScript object notation.
Steps:
Code:
<?php
// Define recursive function to extract nested values
function printValues($arr) {
global $count;
global $values;
// Check input is an array
if(!is_array($arr)){
die("ERROR: Input is not an array");
}
/* Loop through array, if value is itself an array recursively call the function
else add the value found to the output items array, and increment counter by 1 for
each value found */
foreach($arr as $key=>$value){
if(is_array($value)){
printValues($value);
} else{
$values[] = $value;
$count++;
}
}
// Return total count and values found in array
return array('total' => $count, 'values' => $values);
}
// Assign JSON encoded string to a PHP variable
$json = '{
"Student": {
"name": "Sathyabama",
"Mobile": "1234567809",
"E-Mail": "xyz@gmail.com",
"City": "Chennai",
"Details": {
"Dept": "CSE", "Section": "A", "Gender": "Female"
}
}
}';
// Decode JSON data into PHP associative array format
echo "JSON and PHP";
echo"<br> <br>";
$arr = json_decode($json, true);
// Call the function and print all the values
echo "Contents of JSON Object";
echo"<br> <br>";
$result = printValues($arr);
echo "<hr>";
Result:
Thus record has been created and stored in JSON text and printed in the web page
using PHP successfully.
Ex. No. 7
AJAX and DATABASE
Date:
Aim:
Explanation:
A browser built-in XMLHttpRequest object (to request data from a web server)
JavaScript and HTML DOM (to display or use the data)
Steps:
Code:
“cd_catalog.xml”
“Db.html”
<!DOCTYPE html>
<html>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>
<h2> Asynchronous JavaScript And XML </h2>
<button type="button" onclick="loadDoc()">Get my Book collection</button>
<br><br>
<table id="demo"></table>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "cd_catalog.xml", true);
xhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Artist</th><th>Title</th></tr>";
var x = xmlDoc.getElementsByTagName("BOOK");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>
</body>
</html>
Output:
Result:
Thus an application has been developed to fetch information from the database
using AJAX successfully.