WEB TECHNOLOGIES-2-1
WEB TECHNOLOGIES-2-1
// Prompt box
let name = prompt('Enter your name:');
if (name !== null) {
alert('Hello, ' + name + '! Get ready for your exams.');
}
// Confirm box
let confirmation = confirm('Do you want to start your
preparation now?');
if (confirmation) {
alert('Great! Let\'s get started, ' + name + '!');
} else {
alert('Okay, don\'t delay too much, ' + name + '.');
}
b) Write a PHP program to add or append in paragraph text
and also in the numbered (ordered) list in a given HTML
document using jQuery selectors.
php
<!DOCTYPE html>
<html>
<head>
<title>jQuery Append</title>
<script src="https://code.jquery.com/jquery-
3.6.0.min.js"></script>
<script>
$(document).ready(function(){
// Append text to a paragraph
$('#appendTextBtn').click(function(){
$('p#paragraph').append(' Exams are approaching,
prepare well!');
});
// Append new list item to an ordered list
$('#appendListBtn').click(function(){
$('ol#orderedList').append('<li>Start studying for
exams!</li>');
});
});
</script>
</head>
<body>
</body>
</html>
php
<!-- search.php -->
<?php
if (isset($_POST['query'])) {
$query = $_POST['query'];
$students = array("John", "Jane", "Jack", "Jill", "Jessica",
"James");
$output = '<ul>';
foreach ($students as $student) {
if (stripos($student, $query) !== false) {
$output .= '<li>' . $student . '</li>';
}
}
$output .= '</ul>';
echo $output;
}
?>
This example includes a simple HTML interface and a PHP
script. The HTML file contains an input field where users can
type a name. The script sends the input to the search.php file
using Ajax, which searches for matching student names in the
array and returns the results.
Q5) Attempt any one of the following: [3 Marks each]
a) Write XML syntax rules.
• XML Declaration: The declaration should be at the
beginning of the document.
xml
<?xml version="1.0" encoding="UTF-8"?>
• Single Root Element: There must be one and only one
root element that contains all other elements.
xml
<root></root>
• Case Sensitivity: XML tags are case-sensitive.
xml
<Item></Item> <!-- Correct -->
<item></item> <!-- Incorrect if case doesn't match -->
• Proper Nesting: Elements must be properly nested.
xml
<parent>
<child></child>
</parent>
• Attribute Values in Quotes: Attribute values must be
enclosed in quotes.
xml
<element attribute="value"></element>
• Closing Tags: Every element must have a closing tag.
xml
<element></element>
b) What are jQuery selectors? Explain in brief. jQuery
selectors are used to select and manipulate HTML elements.
They are based on CSS selectors and allow you to find and
select HTML elements based on their id, class, tag, attribute,
and more.
• Element Selector: Selects all elements of a specified
type.
javascript
$("p") // Selects all <p> elements
• ID Selector: Selects a single element with a specific ID.
javascript
$("#myId") // Selects the element with ID 'myId'
• Class Selector: Selects all elements with a specific class.
javascript
$(".myClass") // Selects all elements with class 'myClass'
• Attribute Selector: Selects elements with a specified
attribute.
javascript
$("input[type='text']") // Selects all <input> elements with
type 'text'
• Descendant Selector: Selects elements that are
descendants of a specified element.
javascript
$("div p") // Selects all <p> elements that are descendants of
a <div>
These selectors make it easy to access and manipulate the
DOM, enhancing the interactivity and functionality of web
pages.