Name: B K Anirudh REG - NO: 19BIT0348: Digital Assignment 2 Web Technologies
Name: B K Anirudh REG - NO: 19BIT0348: Digital Assignment 2 Web Technologies
WEB TECHNOLOGIES
NAME: B K ANIRUDH
REG.NO: 19BIT0348
1. A parking garage charges a $2.00 minimum fee to park for up to three hours. The
garage charges an additional $0.50 per hour for each hour or part thereof in excess of
three hours. The maximum charge for any given 24-hour period is $10.00. Assume that
no car parks for longer than 24 hours at a time. Write a script that calculates and
displays the parking charges for each customer who parked a car in this garage
yesterday. You should input from the user the hours parked for each customer. The
program should display the charge for the current customer and should calculate and
display the running total of yesterday's receipts. The program should use the function
calculate-Charges to determine the charge for each customer. Use a prompt dialog to
obtain the input from the user.
CODE:
<!DOCTYPE html>
<html>
<head>
<title>19BIT0348</title>
<script type="text/javascript">
function calculate_Charges()
{
if (hours>24)
{charge=10;}
else if(hours>3)
{charge=charge+0.5*(hours-3);}
var total=yesterday+charge;
}
</script>
<body>
CODE:
<!DOCTYPE html>
<html>
<head>
<title>19BIT0348</title>
<style>
body{ margin:0;}
#clock{ width:1 00%;
img{
display: block; height:
60%;
width: 90%;
padding: 5%;
}
input
{margin: 5%;}
form
{padding: 20%;}
</style>
var mm =time.getMinutes();
var ss =time.getSeconds();
hh =zero(hh);
mm =zero(mm);
ss =zero(ss);
function zero(t)
if(t<10)
{t="0"+t;}
return t;
</script>
</head>
<body onload = "clock()">
<div id = "clock"></div>
<div id = "slider">
<script>
var index = 0;
show();
functionshow()
index++;
{index = 1;}
slides[index-1].style.display = "block";
setTimeout(show, 5000);
</script>
<div id = "color">
<form>
<select id="fontFamily">
<option value="arial">Arial</option>
<option value="cambria">Cambria</option>
<option value="consolas">Consolas</option>
<option value="gigi">Gigi</option>
</select>
<select id="fontSize">
<option value="12">12</option>
<option value="16">16</option>
<option value="24">24</option>
<option value="32">32</option>
</select>
<script>
function applyFont()
{
var ff = document.getElementById("fontFamily").value;
document.body.style.fontFamily = ff;
var fs =document.getElementById("fontSize").value;
document.body.style.fontSize = fs;
</script>
</div>
</body>
</html>
OUTPUT:
3. Design a student registration form which takes student name, register number,
DOB,
program, email id, temporary address, permanent address, phone number. Validate
the
following using JavaScript:
a) Mobile number should be exactly 10 digits.
b) Register number should have alphabets and numbers only.
c) Name should not exceed 30 characters and can be only alphabets.
d) Email validation.
e) Provide a checkbox saying “Permanent address is same as temporary address”.
If checked, the value of permanent address should be added automatically from
temp address. And should be in disabled mode.
CODE:
HTML CODE:
<html>
<head>
<title>19BIT0348</title>
</head>
<style>
p {
color: red;
</style>
<body>
<form name="myForm" method="post" onsubmit="return validate()">
<table>
<tr>
<td>Name</td>
<td>
<p id="name"></p>
</td>
</tr>
<tr>
<td>Registration number</td>
<td><input type="text" name="regno"></td>
<td>
<p id="regno"></p>
</td>
</tr>
<tr>
<td>Date Of Birth</td>
<td>
<p id="date"></p>
</td>
</tr>
<tr>
<td>Program</td>
<td>
<p id="program"></p>
</td>
</tr>
<tr>
<td>Email id</td>
<td>
<p id="email"></p>
</td>
</tr>
<tr>
<td>Temporary address</td>
<td><input type="text" name="taddress"></td>
<td>
<p id="taddress"></p>
</td>
</tr>
<tr>
<td>Permanent address same as Temporary address?</td>
<td><input type="checkbox" name="checkbox" onchange="check()"></td>
<td>
<p id="checkbox"></p>
</td>
</tr>
<tr>
<td>Permanent address</td>
<p id="paddress"></p>
</td>
</tr>
<tr>
<td>Phone number</td>
<td>
<p id="phone"></p>
</td>
</tr>
<tr colspan="3">
<td><input type="submit"></td>
</tr>
</table>
</form>
<script src="q3.js"></script>
</body>
</html>
JS CODE:
function validate()
{
var f=0;
var ph=document.forms["myForm"]["phone"].value;
var reg=document.forms["myForm"]["regno"].value;
var name=document.forms["myForm"]["name"].value;
var email=document.forms["myForm"]["email"].value;
if(ph.length==10)
document.getElementById("phone").innerHTML=" ";
f++;
if(reg.match(pattern))
{
document.getElementById("regno").innerHTML=" ";
f++;
pattern=/^[a-z A-Z]{1,30}$/;
if(name.match(pattern))
{
document.getElementById("name").innerHTML=" ";
f++;
}
if(email.match(pattern))
{
document.getElementById("email").innerHTML=" ";
f++;
}
else document.getElementById("email").innerHTML="*please provide correct
email";
if(f==4)
{
alert("form submitted successfully");
return true;
}
function check()
{
var box=document.forms["myForm"]["checkbox"].checked;
var padd=document.forms["myForm"]["paddress"];
var tadd=document.forms["myForm"]["taddress"];
if(box==true)
padd.disabled=true;
padd.value=tadd.value;
}
else
padd.disabled=false;
padd.value="";
}
}
OUTPUT:
4. Write the JavaScript code to add behavior to the following page for manipulating
strings.
a) The page UI allows the user to type a phrase into a text box. The user can click
the "Go!" button to display the words in that phrase in reverse order. Each word
in the phrase should be inserted as a span with a class of word, inside a div with
the id of words. Every other word (the first, third, fifth, etc.) should also be
underlined
b) The user can optionally specify a "filter" text by typing into a text box with the
id of filter. If a non-blank filter is specified, you should exclude any words from
the phrase that contain that filter text, case-insensitively. For example, if the
filter text is "abc", exclude any words containing abc, ABC, aBc, etc.
c) If any words are excluded, under the list of words you should modify the div
with id of count to display text of the form, "5 word(s) filtered out". The code
should work for multiple clicks of the button. On each click it should clear any
previous information you injected. You may assume that words in the phrase are
separated by single spaces.
d) These screenshots show the initial state, and after phrases have been typed and
"Go!" is clicked.
CODE:
<html>
<head>
<title>19BIT0348</title>
</head>
<style>
.word {
border: 1px dotted red;
color: red;
background: pink;
margin-right: 5px;
padding: 4px;
text-decoration: underline;
.word:nth-child(2n) {
text-decoration: none;
</style>
<body>
<h1>Sentence Reverser!</h1>
<table>
<tr>
<td>Phrase:</td>
<tr>
<td>Filter:</td>
</tr>
<tr colspan="2">
<p id="result"></p>
<script src="q4.js"></script>
</body>
</html>
JS CODE:
function reverser()
var str=document.getElementById("phrase").value;
var s="";
var c=0;
var filter=document.getElementById("filter").value;
for(var i=arr.length-1;i>=0;i--)
if(filter=="")
s=s+"<span class=\"word\">"+arr[i]+"</span>";
else
var temp=arr[i];
if(temp.toUpperCase().startsWith(filter.toUpperCase())==false)
s=s+"<span class=\"word\">"+arr[i]+"</span>";
else
c++;
}
}
document.getElementsByClassName("words")[0].innerHTML=s;
<head>
<script>
</script>
</head>
<body>
<br>
<script>
function check() {
var n = document.getElementById("count").value;
if (n < 250) {
} else
document.getElementById("h3").innerText = "Tickets Not Available";
</script>
</body>
</html>
RIGHT:
<html>
<head>
<style>
td {
padding: 8px;
tr:nth-child(2n) td {
padding-top: 0;
tr:nth-child(2n+1) td {
padding-bottom: 0;
}
div {
margin: 0 auto;
position: absolute;
width: 50%;
left: 25%;
right: 25%;
top: 10%;
padding: 0;
}
</style>
</head>
<body>
<div>
<table cellspacing="5px" style="border:2px solid black;width:100%">
<td>Source Station</td>
<td>Destination Station</td>
</tr>
<tr>
<tr>
<td>Train Name</td>
<td>Coach Number</td>
</tr>
<tr>
<td>
<select>
<option >Rajdhani Express</option>
<option >GareebRath</option>
</select>
</td>
<td>
<select>
<option >S1</option>
<option >S2</option>
<option >S3</option>
<option >S4</option>
<option >S5</option>
<option >S6</option>
<option >S7</option>
<option >S8</option>
</select>
</td>
</tr>
<tr>
<td>Date</td>
<td>Time</td>
</tr>
<tr>
<td><input type="date"></td>
<td><input type="time"></td>
</tr>
<tr>
<td>Gender</td>
<td>Count</td>
</tr>
<tr>
<td>
<select>
<option >Male</option>
<option >Female</option>
</select>
</td>
<td>
<input type="number">
</td>
</tr>
<tr>
<td><input type="reset"></td>
</tr>
</form>
</table>
</div>
</body>
</html>
TOP:
<html>
<head>
<style>
body {
background: lightblue
img {
position: absolute;
top: 2px;
left: 5px;
}
h1 {
margin: 0 auto;
position: absolute;
left: 25%;
width: 50%;
top: 25%;
font-family: Roboto;
}
</style>
</head>
<body>
<img src="irctc.png" alt="irctc logo">
<h1 align="center">Online Railway Reservation System</h1>
</body>
</html>
OUTPUT:
6.
i) Design a table in the format given below using HTML and JQuery selectors.
ii) Apply different background for odd and even rows of the table.
iii) Apply different CSS for table header using JQuery selectors.
CODE:
HTML CODE:
<html>
<head>
<title>19BIT0348</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>State</th>
</tr>
</thead>
<tbody>
<tr>
<td>Mannix</td>
<td>Bolton</td>
<td>Merizo</td>
<td>Michigan</td>
</tr>
<tr>
<td>Suki</td>
<td>King</td>
<td>Fairmont</td>
<td>Oklahoma</td>
</tr>
<tr>
<td>Shelby</td>
<td>English</td>
<td>Durham</td>
<td>Arkansas</td>
</tr>
<tr>
<td>Portia</td>
<td>Burns</td>
<td>Priceton</td>
<td>Rhode Island</td>
</tr>
<tr>
<td>Dacey</td>
<td>Young</td>
<td>Covina</td>
<td>South Carolina</td>
</tr>
<tr>
<td>Clark</td>
<td>Reyes</td>
<td>Grand Rapids</td>
<td>New Jersey</td>
</tr>
<tr>
<td>Maris</td>
<td>Decker</td>
<td>Sierra Madre</td>
<td>Georgia</td>
</tr>
</tbody>
</table>
<script src="q6.js"></script>
</body>
</html>
jQuery CODE:
$("td").css("padding","5px 10px");
$("th").css("padding","5px 10px");
$("tbody tr").css({"color":"white","background":"dimgray"});
$("tbody tr:nth-child(2n)").css({"color":"black","background":"white"});
OUTPUT:
7. Write the JQuery code, so that when the Delete button is clicked, any button
whose text
value is divisible by the number written in the text field is removed from the page.
You
may assume that a valid number has been typed in the text field. The HTML code is
the
following:
These screenshots show the initial page and its new appearance after typing 2 into
the
text field and pressing Delete:
CODE
HTML CODE:
<html>
<head>
<title>19BIT0348</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<style>
.btns {
margin-right: 4px;
</style>
</head>
<body>
Divisible by :
<input type="number" id="query">
<div id="buttons"></div>
<script src="q7.js"></script>
</body></html>
JS Code:
var arr = [];
);
arr.push(n);
}
function divide() {
var nu = Number($("#query").val());
console.log(d.text);
if (Number(d.innerHTML) % nu == 0) {
console.log(d.text);
d.style.display = "none";
console.log("deleted");
}
}
OUTPUT:
8. Write the JQuery code to add behavior to the following page for keeping track of
a todo-
list.
a) The page UI allows the user to type an item into a text box. The user can click
the "add" button to add the item to the bottom of the list. Each word in the
phrase should be inserted as a li, inside an ul with the id of list.
b) If the user wishes to remove an item he or she can type the text of the item he or
she wishes to remove in the text box and click the “remove” button. This should
be case insensitive. For example, if the list only contains “foo” and the user tries
to remove “FoO”, it should be removed. If the user tries to remove an item that
is in the list multiple times only the first occurrence should be removed.
c) The items should have background colors that alternate between white and
yellow (first white, then yellow, then white, yellow, etc.). This should still be the
case no matter how many items are removed or added and no matter what order
these operations are done in.
d) The code should work for multiple clicks of the buttons. On each click it should
clear any previous information you typed in the input boxes.
These screenshots show the state after items have been added and the state after
itemshave been removed.
CODE:
HTML CODE:
<html>
<head>
<title>19BIT0348</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<style>
li:nth-child(2n) {
background: yellow;
}
#list {
width: 200px;
}
</style>
<title>19BIT0027</title>
</head>
<body>
<ul id="list"></ul>
JS CODE:
function add() {
$("#list").append(s);
str.val("");
}
function remove() {
str = str.toUpperCase();
var d = $("#list").children();
var n = d.length;
if (d[i].textContent.toUpperCase() == str) {
d[i].remove();
break;
}
$("#inputField").val("");
OUTPUT
9. a) Validate the Event Registration Form given below using Jquery for the
following
conditions.
All fields are mandatory
Zip code should be exactly five digits
Email validation
b) Create an array for a list of cities. Provide autocomplete option for city field using
that array as a source.
CODE:
<html>
<head>
<title>19BIT0348</title>
<style type="text/css">
#break1{
position: absolute;
width:130px;}
#break2{
position: absolute;
width:300px;}
.right{
text-align:right;}
#image{
top:10px;
position:absolute;
background-color:#4E5A66;
#head{
left:150px;
font-family:Arial;
color:white;
position:absolute;
width:750px;
font-size:50px;
top:10px;
background-color:#4E5A66;
#middle{
position:absolute;
top:125px;}
#foot{
width:800px;
background-color:#4E5A66;
position:absolute;
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
var
cities={"UttarPradesh":["Lucknow","Kanpur","Ghaziabad","Agra"],"MadhyaPradesh":["Indore",
"Bhopal",
"Jabalpur","Ujjain"]};
</script>
<script>
var k=0,len=0,max=0,match="",c=0;
$(function()
if($("#autocomp").text()=="")
$("#autocomp").hide();
for(i in cities)
var opt=$("<option></option>").text(i);
opt.attr("value",i);
$("#states").append(opt);
$("#city").keyup(function(){
var state=$("#states").val();
for(j in cities)
{
if(j==state)
//alert(cities[j]);
for(k in cities[j])
//alert($("#city").val().length);
if(cities[j][k].length<$("#city").val().length)
len=cities[j][k].length;
else
len=$("#city").val().length;
//alert(len);
for(var m=0;m<len;m++)
//alert($("#city").val()[m]+" vs
"+cities[j][k][m]);"
if($("#city").val()[m]==cities[j][k][m])
c++;
if($("#city").val()[m]!=cities[j][k][m])
break;
if(c>max)
match=cities[j][k];
c=0;
}
$("#autocomp").show();
$("#autocomp").text(match);
if($("#city").val()=="")
$("#autocomp").text("");
$("#autocomp").hide();
});
$("#autocomp").click(function(){
$("#city").val($("#autocomp").text());
});
$("#sub").click(function(){
var bool=true;
if($("#fname").val()==""||$("#lname").val()==""||$("#mail").val()==""||$("#city").val()==""||$("#
states"
).val()==null||$("#zip").val()==""||$("#meal").val()==null)
bool=false;
if($("#zip").val().test(/^d{5}$/)==null)
bool=false;
if(bool)
$("#form1").submit();
else
{
$("#form1").reset();
});
});
</script>
</head>
<body bgcolor="#D9E0E8">
<span id="image">
<img
src="https://www.bostonhigashi.org/UserFiles/Servers/Server_5286763/Image/Calendars
/calicon.png"
</span>
<span id="head">
</span>
<div id="middle">
<br>
<table>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td class="right">City</td>
<td><input type="text" id="city" /><button id="autocomp"></button></td>
</tr>
<tr>
<td class="right">State</td>
<td><select id="states">
</select></td>
</tr>
<tr>
</tr>
<tr>
<td><span id="break1"></span></td>
<td><span id="break2"></span></td>
</tr>
<tr>
<td>
value="no" />No</td>
</tr>
<tr>
day Pass</td></tr>
<tr>
<td><span id="break1"></span></td>
<td><span id="break2"></span></td>
</tr>
<tr>
<td>Meal Preference</td>
<option value="veg">Vegetarian</option>
</select></td>
<tr>
</table>
<div id="foot">
</div>
</form>
</div>
</body>
</html>
OUTPUT:
10. Write the XHTML code to create the form with the following capabilities
a) A text widget to collect the users name
b) Four check boxes, one each for the following items
i. Four 100 watt light bulbs for Rs. 20=39
ii. Eight 100 watt light bulbs for Rs 40=20
iii. Four 100 watt long life light bulbs for Rs. 30=95
iv. Eight 100 watt long life light bulbs for Rs 70=49
c) A collection of 3 radio buttons that are labeled as follows
i. Visa
ii. Master Card
iii. Discover
d) Computes the total cost of the ordered light bulbs for the above program after
adding 13.5% VAT. The program must inform the buyer of exactly what was
ordered in table.
CODE:
<html>
<title>19BIT0348</title>
<style media="screen">
.checkIt{
display:flex;
}
.quantity{
margin-left: 20px;
.inputPayment,.totalPayment{
width:35%;
.buttons{
}
.main_form{
width:550px;
padding:15px;
label{
margin-top:50px;
}
th,td{
padding:5px;
</style>
<body>
<div class="main_form">
<div class="name">
</div>
<br />
<div class="checkIt">
<div class="check">
<label for="">Four 100 watt light bulbs for Rs.20.39 </label><br />
<label>Four 100 watt long life bulbs for Rs.30.95 </label><br />
<label>Eight 100 watt long life bulbs for Rs.70.49 </label><br />
</div>
<div class="quantity">
<label for="checkbox">Quantity</label><br><br>
<div class="payment">
<label for="">Select the mode of the payment</label><br />
<input id="visa" type ="radio" name="paymode" value="visa"
checked="checked"
class="checkbox_check"/>
class="checkbox_check"/>
<label >Master Card</label><br />
<div class="buttons">
</div>
</form>
<br>
<div id="contents"></div>
<thead>
<th width="65%">Item</th>
<th>Qty</th>
<th>Price</th>
<th>Total</th>
</thead>
<tbody>
<tr>
<td>20.39</td>
<td id="total1"></td>
</tr>
<tr>
<td id="2nd"></td>
<td>40.2</td>
<td id="total2"></td>
</tr>
<tr>
<td>Four 100 watt long life bulbs for Rs.30.95 </td>
<td id="3rd"></td>
<td>30.95</td>
<td id="total3"></td>
</tr>
<tr>
<td id="4th"></td>
<td>70.49</td>
<td id="total4"></td>
</tr>
</tbody>
</table>
<br>
<p id="tax_value"></p>
</div>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></scr
ipt>
<script type="text/javascript">
$(document).ready(function(){
$("input submit").on("click",function(){
$("").each(function(){
if ($('input checkbox_check').not('checked')){
$(this).val();
$("input inputPayment").val("0");
console.log($("input inputPayment").val());
}
});
});
});
$("#submit").click(function(){
var x= $("#username").val();
console.log(x);
$("#contents").text("User Name:"+x);
$("#table").css("opacity","1");
var a = $("#1").val();
var b = $("#2").val();
var c = $("#3").val();
var d = $("#4").val();
if($("#check1").is(':checked')){
$("#1st").text(a);
else{
var a = 0;
$("#1st").text("0");
if($("#check2").is(':checked')){
$("#2nd").text(b);
else{
var b = 0;
$("#2nd").text("0");
}
if($("#check3").is(':checked')){
$("#3rd").text(c);
}
else{
var c = 0;
$("#3rd").text(c);
}
if($("#check4").is(':checked')){
$("#4th").text(d);
else{
var d = 0;
$("#4th").text(d);
var radio="";
if($('#visa').is(':checked')) {
radio = "Visa";
if($('#master_card').is(':checked')){
radio = "Master card";
if($('#discover').is(':checked')){
radio = "Discover";
$("#total1").text(tot1);
$("#total2").text(tot2);
$("#total3").text(tot3);
$("#total4").text(tot4);
var e = tot1+tot2+tot3+tot4;
console.log(e);
var f = 0.135*e;
$("#table").css("opacity","0");
});
</script>
</body>
</html>
OUTPUT: