WTLab
WTLab
Prepared by: -
LAB MANUAL
VISION:
“To impart quality education in engineering and management to meet technological, business
and societal needs through holistic education and research”
MISSION:
VISION:
“To produce quality Computer Science professional, possessing excellent technical knowledge,
skills, personality through education and research.”
MISSION:
6 Apply HTML, CSS and JavaScript to design a simple calculator to perform the following
operations: sum,
product, difference, remainder, quotient, power, square-root and square.
7 Develop JavaScript program (with HTML/CSS) for:
a) Converting JSON text to JavaScript Object
b) Convert JSON results into a date
c) Converting From JSON To CSV and CSV to JSON
d)Create hash from string using crypto.createHash() method
8 a. Develop a PHP program (with HTML/CSS) to keep track of the number of visitors
visiting the web page and to display this count of visitors, with relevant headings.
b. Develop a PHP program (with HTML/CSS) to sort the student records which are
stored in the
database using selection sort.
9 Develop jQuery script (with HTML/CSS) for:
a. Appends the content at the end of the existing paragraph and list.
b. Change the state of the element with CSS style using animate() method
Change the color of any div that is animated.
10 Develop a JavaScript program with Ajax (with HTML/CSS) for:
a. Use ajax() method (without Jquery) to add the text content from the text file by sending
ajax request.
b. Use ajax() method (with Jquery) to add the text content from the text file by sending ajax
request.
c.Illustrate the use of getJSON() method in jQuery
Illustrate the use of parseJSON() method to display JSON values.
Programming Assignment (5 marks):
Construct a Website (multiple Web pages) containing ‘Resume’ and Bio -data by using relevant HTML
elements and
appropriate styling for presentation with CSS/jQuery/JavaScript. Host the Website on a cloud platform.
Programming Assignment (5 marks): Build a Web application with HTML, CSS, JavaScript, jQuery and
PHP for
online application/registration form. Form should accept the information and print/display on a
browser with formatting/styling upon submission (Button click) on success. Host the application on a
cloud platform.
Course outcomes (Course Skill Set):
At the end of the course, the student will be able to:
● Design the experiment for the given problem using HTML, Javascript and CSS.
● Develop the solution for the given real-world problem using jQuery, Ajax and PHP.
Analyze the results and produce substantial written documentation.
● Each experiment is to be evaluated for conduction with an observation sheet and record write-
up. Rubrics for the evaluation of the journal/write-up for hardware/software experiments are
designed by the faculty who is handling the laboratory session and are made known to students
at the beginning of the practical session.
● Record should contain all the specified experiments in the syllabus and each experiment write-
up will be evaluated for 10 marks.
● Total marks scored by the students are scaled down to 30 marks (60% of maximum marks).
● Weightage to be given for neatness and submission of record/write-up on time.
● Department shall conduct a test of 100 marks after the completion of all the experiments listed
in the syllabus.
● In a test, test write-up, conduction of experiment, acceptable result, and procedural
knowledge will carry a weightage of 60% and the rest 40% for viva-voce.
● The suitable rubrics can be designed to evaluate each student’s performance and learning ability.
● The marks scored shall be scaled down to 20 marks (40% of the maximum marks).
The Sum of scaled-down marks scored in the report write-up/journal and marks of a test is the total CIE
marks scored by the student.
Semester End Evaluation (SEE):
● SEE shall be conducted jointly by the two examiners of the same institute, examiners are
appointed by the Head of the Institute.
● The examination schedule and names of examiners are informed to the university before the
conduction of the examination. These practical examinations are to be conducted between the
schedule mentioned in the academic calendar of the University.
● (Rubrics) Breakup of marks and the instructions printed on the cover page of the answer script
to be strictly adhered to by the examiners. OR based on the course requirement evaluation
rubrics shall be decided jointly by examiners.
● Students can pick one question (experiment) from the questions lot prepared by the examiners
jointly.
● Evaluation of test write-up/ conduction procedure and result/viva will be conducted jointly by
examiners.
General rubrics suggested for SEE are mentioned here, writeup-20%, Conduction procedure and
result in -60%, Viva-voce 20% of maximum marks. SEE for practical shall be evaluated for 100
marks and scored marks shall be scaled down to 50 marks (however, based on course type, rubrics
shall be decided by the examiners)
Change of experiment is allowed only once and 15% of Marks allotted to the procedure part are to
be made zero.
The minimum duration of SEE is 02 hours
Web Links:
● https://www.w3schools.com/html/default.asp
● https://www.w3schools.com/css/default.asp
● https://www.w3schools.com/js/js_examples.asp
● https://www.geeksforgeeks.org/javascript-examples/
● https://www.w3schools.com/php/default.asp
● https://www.w3schools.com/jquery/default.asp
● https://www.w3schools.com/js/js_ajax_intro.asp
● https://www.geeksforgeeks.org/jquery-tutorial/
Xampp Folder:
open visual code -> file -> open folder ->local disk c -> xampp -> htdocs -> create new folder ->
select folder -> trusted window
open ->local disk c -> xampp -> htdocs ->dashboard -> index -> open in notepad -> insert your
folder name -> save.
...Url: localhost/dashboard/usn
Program-1
Develop the HTML page named as “Myfirstwebpage.html”. Add the following tags with
relevant content.
c) Paragraph
d) Horizontal line
e) Line Break
f) Block Quote
g) Pre tag
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- <style>
body {
line-height: 1.6;
margin: 0;
padding: 20px;
</style> -->
</head>
<body>
<p>This is a paragraph. It demonstrates the use of the paragraph tag in HTML. Paragraphs are
used to group related content together. </p>
<hr>
<p>This is another paragraph. <br>This text appears on a new line due to the line break tag.
</p>
<blockquote>
This is a block quote. It's often used to highlight quoted text from another source.
</blockquote>
<pre>
</pre>
<p>
<b>Bold text</b><br>
<i>Italic text</i><br>
<u>Underlined text</u><br>
<strong>Strong text</strong><br>
<em>Emphasized text</em><br>
</p>
</body>
</html>
Output:
Program -2
Develop the HTML page named as “Table.html” to display your class time table.
a) Provide the title as Time Table with table header and table footer, row-span and col-
span etc.
b) Provide various colour options to the cells (Highlight the lab hours and elective hours
with different colours.)
c) Provide colour options for rows
Source Code: Table.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Table</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
.lab-hours {
background-color: #ffcccb;
}
.elective-hours {
background-color: #90ee90;
}
.lunch {
background-color: #ffd700;
}
.odd-row {
background-color: #f8f8f8;
}
tfoot {
background-color: #e6e6e6;
font-weight: bold;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th colspan="7">Class Time Table</th>
</tr>
<tr>
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
</tr>
</thead>
<tbody>
<tr>
<td>9:00 - 10:00</td>
<td>Math</td>
<td>English</td>
<td>Science</td>
<td>History</td>
<td>Geography</td>
<td rowspan="6">No Classes</td>
</tr>
<tr class="odd-row">
<td>10:00 - 11:00</td>
<td>Physics</td>
<td>Chemistry</td>
<td>Biology</td>
<td class="elective-hours">Computer Science</td>
<td class="elective-hours">Art</td>
</tr>
<tr>
<td>11:00 - 12:00</td>
<td class="lab-hours" colspan="2">Physics Lab</td>
</body>
</html>
Output:
Program - 3
Develop an external style sheet named as “style.css” and provide different styles for h2, h3,
hr, p, div, span, time, img & a tags. Apply different CSS selectors for tags and demonstrate
the significance of each.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<main id="main-content">
<p>This is a paragraph right after an h2. It demonstrates the adjacent sibling selector.</p>
<hr>
<p lang="en">This paragraph has a lang attribute, demonstrating the attribute selector.</p>
<section>
</section>
<article class="special">
</article>
<img
src="https://d3njjcbhbojbot.cloudfront.net/api/utilities/v1/imageproxy/https://images.ctfassets.net
/wp1lcwdav1p1/6z473u5f7WaFUnr9GxDEk2/085274c4a841bd2dc900ebca36c43c9c/GettyImag
es-
1255905237.jpg?w=1500&h=680&q=60&fit=fill&f=faces&fm=jpg&fl=progressive&auto=form
at%2Ccompress&dpr=1&w=1000" alt="A placeholder image">
</main>
</body>
</html>
style.css
/* Element Selector */
h2 {
color: #2c3e50;
padding-bottom: 10px;
h3:hover {
color: #e74c3c;
cursor: pointer;
/* Element Selector */
hr {
border: 0;
height: 1px;
p[lang] {
font-style: italic;
/* Class Selector */
.highlight {
background-color: #f1c40f;
padding: 5px;
/* ID Selector */
#main-content {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #ecf0f1;
/* Descendant Selector */
div p {
line-height: 1.6;
margin-bottom: 15px;
/* Child Selector */
font-weight: bold;
color: #16a085;
h2 + p {
font-size: 1.1em;
color: #7f8c8d;
/* Attribute Selector */
time[datetime] {
color: #8e44ad;
font-weight: bold;
/* Pseudo-element Selector */
p::first-letter {
font-size: 1.5em;
font-weight: bold;
color: #c0392b;
/* Multiple Selectors */
img, a {
padding: 5px;
a:link, a:visited {
color: #3498db;
text-decoration: none;
a:hover, a:active {
color: #e74c3c;
text-decoration: underline;
img[alt] {
max-width: 100%;
height: auto;
/* Combining Selectors */
div.special p {
text-indent: 20px;
color: #27ae60;
Output:
Program-4
Develop HTML page named as “registration.html” having variety of HTML input
elements with background colors, table for alignment & provide font colors & size using
CSS styles.
Source Code: registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
text-align: center;
}
table {
width: 100%;
max-width: 600px;
margin: 0 auto;
background-color: #c08686;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
td {
padding: 10px;
}
label {
color: #555;
font-weight: bold;
}
input[type="text"], input[type="email"], input[type="password"], select, textarea {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
font-size: 16px;
}
input[type="radio"], input[type="checkbox"] {
margin-right: 5px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 18px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.error {
color: #ff0000;
font-size: 14px;
}
</style>
</head>
<body>
<h1>Registration Form</h1>
<form action="#" method="post">
<table>
<tr>
<td><label for="fullname">Full Name:</label></td>
<td><input type="text" id="fullname" name="fullname" required></td>
</tr>
<tr>
<td><label for="email">Email:</label></td>
<td><input type="email" id="email" name="email" required></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" id="password" name="password" required></td>
</tr>
<tr>
<td><label for="confirm_password">Confirm Password:</label></td>
<td><input type="password" id="confirm_password" name="confirm_password"
required></td>
</tr>
<tr>
<td><label>Gender:</label></td>
<td>
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female" required>
<label for="female">Female</label>
<input type="radio" id="other" name="gender" value="other" required>
<label for="other">Other</label>
</td>
</tr>
<tr>
<td><label for="birthdate">Date of Birth:</label></td>
<td><input type="date" id="birthdate" name="birthdate" required></td>
</tr>
<tr>
<td><label for="country">Country:</label></td>
<td>
<select id="country" name="country" required>
<option value="">Select a country</option>
<option value="usa">India</option>
<option value="uk">United Kingdom</option>
<option value="canada">Canada</option>
<option value="australia">Australia</option>
<option value="other">Other</option>
</select>
</td>
</tr>
<tr>
<td><label for="interests">Interests:</label></td>
<td>
<input type="checkbox" id="sports" name="interests[]" value="sports">
<label for="sports">Sports</label>
<input type="checkbox" id="music" name="interests[]" value="music">
<label for="music">Music</label>
<input type="checkbox" id="reading" name="interests[]" value="reading">
<label for="reading">Reading</label>
<input type="checkbox" id="travel" name="interests[]" value="travel">
<label for="travel">Travel</label>
</td>
</tr>
<tr>
<td><label for="bio">Bio:</label></td>
<td><textarea id="bio" name="bio" rows="4"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" value="Register">
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
Program-5
Develop HTML page named as “newpaper.html” having variety of HTML semantic
elements with background colors, text-colors & size for figure, table, aside, section, article,
header, footer… etc.
Source code: newpaper.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Daily Chronicle</title>
<style>
body {
font-family: 'Georgia', serif;
line-height: 1.6;
color: #333;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f4f4f4;
}
header {
background-color: #1a1a1a;
color: #fff;
padding: 20px;
text-align: center;
}
header h1 {
margin: 0;
font-size: 2.5em;
}
nav {
background-color: #333;
color: #fff;
padding: 10px;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: flex;
justify-content: center;
}
nav ul li {
margin: 0 10px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
main {
display: flex;
margin-top: 20px;
}
section {
flex: 2;
margin-right: 20px;
}
article {
background-color: #fff;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
article h2 {
color: #1a1a1a;
font-size: 1.8em;
}
aside {
flex: 1;
background-color: #e6e6e6;
padding: 20px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
figure {
margin: 0;
text-align: center;
}
figure img {
max-width: 100%;
height: auto;
}
figcaption {
font-style: italic;
color: #666;
font-size: 0.9em;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
footer {
background-color: #1a1a1a;
color: #fff;
text-align: center;
padding: 10px;
margin-top: 20px;
}
</style>
</head>
<body>
<header>
<h1>The Daily Chronicle</h1>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Politics</a></li>
<li><a href="#">Technology</a></li>
<li><a href="#">Sports</a></li>
<li><a href="#">Entertainment</a></li>
</ul>
</nav>
<main>
<section>
<article>
<h2>Breaking News: Major Technological Breakthrough</h2>
<p>Scientists have announced a groundbreaking discovery in the field of quantum
computing, potentially revolutionizing the tech industry.</p>
<figure>
<img
src="https://www.cnet.com/a/img/resize/c7cb26e927bebaa784fb55a01e71d7fecb15d2e3/hub/20
19/06/26/3f76e99d-8055-46f3-8f27-558ee276b665/20180405-ibm-q-quantum-computer-
02.jpg?auto=webp&fit=crop&height=675&width=1200" alt="Quantum Computer">
<figcaption>A state-of-the-art quantum computer at the research
facility</figcaption>
</figure>
</article>
<article>
<h2>Local Sports Team Wins Championship</h2>
<p>In a thrilling match, our local team secured victory in the national championship,
bringing pride to our city.</p>
<table>
<tr>
<th>Team</th>
<th>Score</th>
</tr>
<tr>
<td>Local Heroes</td>
<td>3</td>
</tr>
<tr>
<td>Visiting Challengers</td>
<td>2</td>
</tr>
</table>
</article>
</section>
<aside>
<h3>Weather Update</h3>
<p>Expect sunny skies with a high of 75°F (24°C) today.</p>
<h3>Upcoming Events</h3>
<ul>
<li>City Festival - This Weekend</li>
<li>Tech Conference - Next Month</li>
<li>Charity Run - In Two Weeks</li>
</ul>
</aside>
</main>
<footer>
<p>© 2024 The Daily Chronicle. All rights reserved.</p>
</footer>
</body>
</html>
Output:
Program -6
Apply HTML, CSS and JavaScript to design a simple calculator to perform the following
operations: sum, product, difference, remainder, quotient, power, square-root and square.
(Using PHP)
<html>
<head>
<style>
table, td, th {
width: 35%;
text-align: center;
background-color: lightgray;
input,p { text-align:right; }
</style>
</head>
<body>
<table>
<tr>
<tr>
</tr>
</form>
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
echo "</table>";
else
?>
</body>
</html>
(Using JavaScript)
<!DOCTYPE HTML>
<html>
<head>
<style>
table, td, th
width: 33%;
text-align: center;
background-color: DarkGray;
border-collapse: collapse;
input {text-align:right; }
</style>
<script type="text/javascript">
function calc(clicked_id)
if (isNaN(val1)||isNaN(val2))
else if(clicked_id=="add")
document.getElementById("answer").value=val1+val2;
else if(clicked_id=="sub")
document.getElementById("answer").value=val1-val2;
else if(clicked_id=="mul")
document.getElementById("answer").value=val1*val2;
else if(clicked_id=="div")
document.getElementById("answer").value=val1/val2;
else if(clicked_id=="mod")
document.getElementById("answer").value=val1%val2;
else if(clicked_id=="square")
document.getElementById("answer").value=val1*val1;
else if(clicked_id=="power")
document.getElementById("answer").value=val2*val2;
else if(clicked_id=="root")
document.getElementById("answer").value=(Math.sqrt(val1));
function cls()
value1.value="0";
value2.value="0";
answer.value="";
</script>
</head>
<body>
<table>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr><tr>
</tr>
<tr>
</tr>
</table
</body>
</html>
Output:
Program-7
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<style>
body {
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
.container {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
h1 {
color: #333;
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
button {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
button:hover {
background-color: #45a049;
#result {
margin-top: 20px;
padding: 10px;
background-color: #e7e7e7;
border-radius: 4px;
</style>
</head>
<body>
<div class="container">
<div id="result"></div>
</div>
<script>
function convertJsonToObject() {
try {
} catch (error) {
function convertJsonToDate() {
try {
} catch (error) {
function convertJsonToCsv() {
try {
const csvRows = [
headers.join(','),
];
} catch (error) {
function convertCsvToJson() {
try {
obj[header] = values[index];
return obj;
}, {});
});
} catch (error) {
function createHash() {
try {
} catch (error) {
</script>
</body>
</html>
Output:
b) Convert JSON to Date: input should be given in the format of {"date": "2023-05-
15T12:00:00Z"}
c) Convert JSON to CSV and CSV to JSON: Input should be given in the format of [{
"name": "John", "age": 30, "city": "New York" }, { "name": "Jane", "age": 25, "city":
"Los Angeles" }] for convention JSON to CSV and From converting CSV to JSON the input
should be given as :
name,age,gender
john,20,male
jane,30,female
bob,25,male
d) Create Hash from String: Input should be given in the format of "Hello, World!"
Program - 8A
Develop a PHP program (with HTML/CSS) to keep track of the number of visitors visiting
the webpage and to display this count of visitors, with relevant headings
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Visitor Counter</title>
<style>
body {
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
h1 {
color: #333;
text-align: center;
.counter {
font-size: 24px;
text-align: center;
margin-top: 20px;
</style>
</head>
<body>
<div class="container">
<div class="counter">
<?php
$counterFile = 'count.txt';
if (file_exists($counterFile)) {
$count = (int)file_get_contents($counterFile);
} else {
$count = 0;
$count++;
file_put_contents($counterFile, $count);
$name="counter.txt";
$file = fopen($name,"r");
$hits= fscanf($file,"%d");
fclose($file);
$hits[0]++;
$file = fopen($name,"w");
fprintf($file,"%d",$hits[0]);
fclose($file);
?>
</div>
</div>
</body>
</html>
Output:
Program - 8B
Develop a PHP program (with HTML/CSS) to sort the student records which are stored in
the database using selection sort.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
.container {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
h1 {
color: #333;
text-align: center;
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
th, td {
padding: 10px;
text-align: left;
th {
background-color: #f2f2f2;
</style>
</head>
<body>
<div class="container">
<h1>Student Records</h1>
<?php
$host = 'localhost';
$dbname = 'nkg';
$username = 'root';
$password = '';
try {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$students = $stmt->fetchAll(PDO::FETCH_ASSOC);
$min_idx = $i;
$min_idx = $j;
if ($min_idx != $i) {
$temp = $arr[$i];
$arr[$i] = $arr[$min_idx];
$arr[$min_idx] = $temp;
selectionSort($students, count($students));
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>GPA</th></tr>";
echo "<tr>";
echo "</tr>";
echo "</table>";
} catch(PDOException $e) {
?>
</div>
</body>
</html>
Output:
commands in shell:
>>mysql -u root
>>show databases;
>>show databases;
>> create table student (usn varchar(30), name varchar(30), marks varchar(10));
OR
...localhost/dashboard -> phpMyAdmin ->craete a database name as nkg -> create a table
as students -> insert the column names.
Program-9
Develop jQuery script (with HTML/CSS) for:
a. Appends the content at the end of the existing paragraph and list.
b. Change the state of the element with CSS style using animate() method
c. Change the color of any div that is animated.
Source Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Append, Animate, and Color Change Demo</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1, h2 {
color: #333;
}
.box {
width: 100px;
height: 100px;
background-color: #3498db;
margin: 20px 0;
}
button {
padding: 10px 15px;
background-color: #2ecc71;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #27ae60;
}
</style>
</head>
<body>
<div class="container">
<h1>jQuery Demonstration</h1>
<ul id="existingList">
<li>Existing item 1</li>
<li>Existing item 2</li>
</ul>
<input type="text" id="appendInput" placeholder="Enter text to append">
<button id="appendButton">Append Content</button>
<script>
$(document).ready(function() {
// a. Append content
$("#appendButton").click(function() {
var userInput = $("#appendInput").val();
$("#existingList").append("<li>" + userInput + "</li>").append("<h4>New data
Appended</h4>");
});
// b. Animate element
$("#animateButton").click(function() {
$("#animateBox").animate({
width: "200px",
height: "200px",
opacity: 0.5
}, 1000);
});
Output:
Program-10
Develop a JavaScript program with Ajax (with HTML/CSS) for:
a. Use ajax() method (without Jquery) to add the text content from the text file by sending
ajax request.
b. Use ajax() method (with Jquery) to add the text content from the text file by sending ajax
request.
c. Illustrate the use of getJSON() method in jQuery
d. Illustrate the use of parseJSON() method to display JSON values.
Source Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajax Demo Program</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
</style>
</head>
<body>
<div class="container">
<h1>Ajax Demo Program</h1>
<script>
// Simulated data
const simulatedData = {
text: "This is a sample text from a simulated server response.",
json: {
}, 500);
}).done(function(result) {
$("#result-c").text(JSON.stringify(result, null, 2));
});
}
Output:
• Semantic HTML is a coding style where the tags embody what the text is meant to
convey.
• In Semantic HTML, tags like < b> < /b> for bold, and < i> < /i> for italic should not be
used, reason being they just represent formatting, and provide no indication of meaning
or structure.
• The semantically correct thing to do is use < strong> < /strong> and < em> < /em> .
• These tags will have the same bold and italic effects, while demonstrating meaning and
structure (emphasis in this case).
5. How do you insert a copyright symbol on a browser page?
To insert the copyright symbol, you need to type © or & #169; in an HTML file.
6. Is there any way to keep list elements straight in an html file?
• If you indent each sub nested list in further than the parent list that contains it, you can at
a glance determine the various lists and the elements that it contains.
7. Does a hyperlink apply to text only?
No, hyperlinks can be used on text as well as images. That means you can
convert an image into a link that will allow user to link to another page when
clicked. Just surround the image within the < a href=” “> …< /a> tag
combinations.
• However, font families, URLs to images, and other direct references with the style sheet
may be.
• The trick is that if you write a document using an XML declaration and an XHTML
doctype, then the CSS class names will be case sensitive for some browsers.
13. What are the limitations of CSS ?
Limitations are:
• No expressions
• No column declaration
• It is a string of individual selectors separated by white space (search pattern), where only
the last element in the pattern is addressed providing it matches the specified context
16. What are Pseudo Classes?
Pseudo classes allow you to identify HTML elements on characteristics (as
opposed to their name or attributes). The classes are specified using a colon to
separate the element name and pseudo class. A good example is the :link and
:visited pseudo classes for the HTML A element. Another good example is first_child, which
finds an element’s first child element.
What does z-index do?
The z-index property specifies the stack order of an element. An element with
greater stack order is always in front of an element with a lower stack order.
Here is the Example, where using z-index property you can display in front of
image.
17. What is parent-child selector?
Parent-child selector is a selector representing the direct descendent of a parent
element. Parent-child selectors are created by listing two or more tilde (~)
separated selectors.
BODY ~ P {background: red; color: white}
The P element will be declared the specified style only if it directly descends from the BODY
element:
18. Enumerate the differences between Java and JavaScript?
• Primitive
• Reference types
28. What is the use of type of operator?
'Typeof' is an operator which is used to return a string description of the type of a
variable.
30. Explain window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded.
This leads to a substantial delay before any code is executed. onDocumentReady
loads the code just after the DOM is loaded. This allows early manipulation of
the code.
31. Define event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if
the handler of the child is clicked, the handler of parent will also work as if it
were clicked too.
32. How are event handlers utilized in JavaScript?
Events are the actions that result from activities, such as clicking a link or filling a
form, by the user. An event handler is required to manage proper execution of all
these events. Event handlers are an extra attribute of the object. This attribute
includes event's name and the action taken if the event takes place.
33. What is the correct and the most two common way to start and finish a PHP
block of code?
The two most common ways to start and finish a PHP script are:
<?php [ --- PHP code---- ] ?> and <? [--- PHP code ---] ?>
34. How can we display the output directly to the browser?
To be able to display the output directly to the browser, we have to use the
special tags <?= and ?>.
35. How can PHP and HTML interact?
It is possible to generate HTML through PHP scripts, and it is possible to pass
pieces of information from HTML to PHP.
36. What type of operation is needed when passing values through a form or an
URL?
If we would like to pass values through a form or an URL, then we need to
encode and to decode them using htmlspecialchars() and urlencode().
37. How can PHP and Javascript interact?
PHP and Javascript cannot directly interact since PHP is a server side language
and Javascript is a client-side language. However, we can exchange variables
since PHP can generate Javascript code to be executed by the browser and it is
possible to pass specific variables back to PHP via the URL
38.What is JSON?
JSON stands for JavaScript Object Notation but it does not use JavaScript to perform operations,
it just uses the JavaScript syntax. It is a light-weighted and language-independent format mainly
used to transmit the data between the server and the web app.
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
40. Who created JSON?
Douglas Crockford was the first man who introduced and created the JSON format first in 2000.
• It is a light weight format that helps to optimize the performance of the web app.
• Number
• Boolean
• String
• Array
• Object
• null
45. How to create a JSON array?
A JSON array is just like the arrays in the other programming languages that contains a
collection of multiple items of different data-types. It can contain value of any data-type
supported by JSON.
["value1", 12, true, null]
46. Is it possible to create function in JSON?
No, as we know JSON is just a data format and it is used to transfer data on the network.
Therefore, we can not write any kind of executable code inside it.
const JSONObj = {
"name": "GFG",
"est": "2009",
"workForce": "200+"
}
console.log(JSONObj.name)
console.log(JSONObj.est)
console.log(JSONObj.workForce)
49. Explain the process of accessing JSON object values using square brackets.
You can follow the below syntax to retrieve values of JSON object using square brackets.
}'
console.log(JSONObj["name"])
console.log(JSONObj["est"])
console.log(JSONObj["workForce"])
13. Explain JSONP and how it is different from JSON?
JSONP stands for JSON with Padding. It is a method for sending the JSON data with padding to
avoid cross domain restrictions. JSONP is different from JSON, because it allows the cross-
origin requests.
• Google Chrome
• Mozilla Firefox
• Safari
• Microsoft Edge
• Opera, etc.
51. Explain the use of JSON.parse() method in JSON.
The JSON.parse() method is used to parse the JSON data into JavaScript and converts the JSON
string into a JavaScript object.
JSON.parse(JSONString, function)
52. What is the JSON.stringify() method used for?
The JSON.stringify() method is used to convert the JavaScript object into a JSON string format.
JSON.stringify(JSONString, function, space)
53. Explain JSON schema.
JSON schema is a content specification language defined to validate the structure and the format
of JSON data or string. It defines the basic structure, format and important constraints of JSON
data.
<script type="application/json">
// JSON data
</script>
55. What are the methods used to encode and decode JSON in PHP?
We can use the below methods to encode and decode JSON in PHP:
json_encode(): This method is used to encode JSON in PHP. It takes the data in PHP array
format and converts it into JSON data.
json_decode(): It is used to decode JSON in PHP. It takes a JSON string as input and returns
corres[ponding PHP array.
56. What is the MIME type for JSON?
The MIME type for JSON is application/json. You can pass this type as an value to the type
attribute inside the script tag to include JSON into your HTML document.
• It is not safe to use with untrusted services and browsers as it does not have a solid
security mechanism.
• It can output a complex data in case of large data set which may be difficult to
understand.
59. What are the applications of JSON?
• There are multiple web services and APIs available on the internet that returns the data in
JSON format when the data is fetched from them using JavaScript or any other language.
• lodash
• underscore.js
• jsonwebtoken, etc.
61. How to handle JSON parsing errors in JavaScript?
The JSON parsing errors can be handled using the try/catch block with the parsing statements in
JavaScript.
• YAML
• MessagePack