You are on page 1of 18

Get Mid Term

<html>
<body>
<p>Click the button to get the value of the onclick attribute of the button
element.</p>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> Internet Explorer 8 and earlier does not support the
getNamedItem method.</p>
<p id="demo"></p>
<script>
function myFunction() {
var a = document.getElementsByTagName("BUTTON")[0];
var x = a.attributes.getNamedItem("onclick").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

Button Array

<html>
<body>

<p>Click the button to get the value of the onclick attribute of the button
element.</p>

<button onclick="myFunction()">Try it</button>


<button onclick="myFunction1()">Try it</button>
<button onclick="myFunction2()">Try it</button>
<p><strong>Note:</strong> Internet Explorer 8 and earlier does not support the
getNamedItem method.</p>

<p id="demo"></p>

<script>
var a = document.getElementsByTagName("BUTTON");
function myFunction() {
var x = a[0].attributes.getNamedItem("onclick").value;
document.getElementById("demo").innerHTML = x;
}
function myFunction1() {
var x = a[1].attributes.getNamedItem("onclick").value;
document.getElementById("demo").innerHTML = x;
}
function myFunction2() {
var x = a[2].attributes.getNamedItem("onclick").value;
document.getElementById("demo").innerHTML = x;
}

</script>

</body>
</html>

Resume Using Lists

<html>
<head>
<title> Resume Using Html</title>
</head>
<body>
<center> <h1 style="color:blue;"> <b> <u> Yashwanth Reddy </u> </b> </h1>
</center>
<center> <h2 style="color:red;"> <b> <u> 19BCE7362 </u> </b></h2> </center>

<h2> <b> OBJECTIVE: </b> </h2>Seeking a position as an administrative


assistant at Acme Inc.,
to leverage organizational and research skills to support
internal and
external communication. <br>
<h2> <b> Education Qualifications: </b> </h2>
<ol type="a">
<li> Persuaing Engineering in Computer Science from Vellore Institute of
Technology </li>
<li> Completed Intermedieate in Narayana Junior Collage </li>
<li> Completed Secondary Education in Peepal Grove International School
</li>
</ol>

<h2><b> Hobbies </b> </h2>


<ol type="a">
<li> Playing Games </li>
<li> Waching TV </li>
<li> Reading Books</li>
</ol>

<h2><b> Personal Details </b> </h2>


<ol type="a">
<li> Father Name - Harinatha Reddy </li>
<li> Address - Flat no 101, Spring Field Apartments Madanapalle</li>
<li> Email - yashwanth.19bce7362@vitap.ac.in</li>
</ol>
<h3> <b> Signature </b> </h3>
Yashwanth

</body>

</html>
Resume using Tables

<html>
<head>
<title> Resume Using Html</title>
</head>
<body>
<center> <h1 style="color:blue;"> <b> <u> Yashwanth Reddy </u> </b> </h1>
</center>
<center> <h2 style="color:red;"> <b> <u> 19BCE7362 </u> </b></h2> </center>

<h2> <b> OBJECTIVE: </b> </h2>Seeking a position as an administrative


assistant at Acme Inc.,
to leverage organizational and research skills to support
internal and
external communication. <br>
<center> <table border=1>
<caption> <h2> <b> Education Qualifications: </b> </h2> </caption>
<tr>
<th> S.No </th>
<th> Qualification </th>
<th> Institute </th>
<th> Percentage </th>
</tr>

<tr>
<th> 1 </th>
<th> Engineering in Computer Science </th>
<th> Vellore Institute of Technology </th>
<th> Still Persuaing</th>
</tr>

<tr>
<th> 2 </th>
<th> Intermedieate </th>
<th> Narayana Junior Collage </th>
<th> 96% </th>
</tr>
<tr>
<th> 3 </th>
<th> Secondary Education </th>
<th> Peepal Grove International School </th>
<th> 92% </th>
</tr>
</table>
</center>

<table border=1, align="center">


<caption> <h2> <b> Hobbies: </b> </h2> </caption>
<tr>
<th> S.No </th>
<th> Hobby </th>
<th> Description </th>
</tr>

<tr>
<th> 1 </th>
<th> Playing Games </th>
<th> Games like Call of Duty , Basket Ball </th>
</tr>

<tr>
<th> 2 </th>
<th> Reading Books </th>
<th> I will read books in My Free Time </th>
</tr>

<tr>
<th> 3 </th>
<th> Waching Netflix </th>
<th> I will Watch Netflix when i have Free time </th>
</tr>
</table>

<table border=1, align="center">


<caption> <h2> <b> Personal details: </b> </h2> </caption>
<tr>
<th> Father Name</th>
<th> Harinatha Reddy</th>
</tr>

<tr>
<th> Email</th>
<th> yashwanth.19bce7362@vitap.ac.in </th>
</tr>

<tr>
<th> Address</th>
<th> Flat no 101, Spring Field Apartments Madanapalle </th>
</tr>

</table>

<h3> <b> Signature </b> </h3>


<font style="color:blue">Yashwanth </font>

</body>
</html>
JS Array

Change Element

var​ cars = [​"Saab"​, ​"Volvo"​, ​"BMW"​];


cars[​0​] = ​"Opel"​;
document.getElementById(​"demo"​).innerHTML = cars[​0​];

var​ person = {firstName:​"John"​, lastName:​"Doe"​, age:​46​};

var​ x = cars.length; ​// The length property returns the number


of elements
var​ y = cars.sort(); ​// The sort() method sorts arrays

Length

var​ fruits = [​"Banana"​, ​"Orange"​, ​"Apple"​, ​"Mango"​];


fruits.length;

Array Loop
fruits = [​"Banana"​, ​"Orange"​, ​"Apple"​, ​"Mango"​];
fLen = fruits.length;
text = ​"<ul>"​;
for​ (i = ​0​; i < fLen; i++) {
text += ​"<li>"​ + fruits[i] + ​"</li>"​;
}
text += ​"</ul>"​;
Add Array
var​ fruits = [​"Banana"​, ​"Orange"​, ​"Apple"​, ​"Mango"​];
fruits.push(​"Lemon"​);
Form Validation
function​ validateForm() {
​var​ x = document.forms[​"myForm"​][​"fname"​].value;
​if​ (x == ​""​) {
alert(​"Name must be filled out"​);
​return​ ​false​;
}
}
<​form​ name​="myForm"​ action​="/action_page.php"​ onsubmit​="return
validateForm()"​ method​="post">
Name: ​<​input​ type​="text"​ name​="fname">
<​input​ type​="submit"​ value​="Submit">
<​/form​>

Validation

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Can Validate Input</h2>

<p>Please input a number between 1 and 10:</p>

<input id="numb">

<button type="button" onclick="myFunction()">Submit</button>

<p id="demo"></p>
<script>
function myFunction() {
var x, text;

// Get the value of the input field with id="numb"


x = document.getElementById("numb").value;

// If x is Not a Number or less than one or greater than 10


if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>
Ajax

<!DOCTYPE html>
<html>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>

<h2>The XMLHttpRequest Object</h2>

<button type="button" onclick="loadDoc()">Get my CD


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("CD");
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>

Ajax

<!DOCTYPE html>
<html>
<body>

<div id="demo">
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Change
Content</button>
</div>

<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
</script>

</body>
</html>

The getResponseHeader() Method

The ​getResponseHeader()​ method returns specific header information


from the server response.

<!DOCTYPE html>
<html>
<body>

<h2>The XMLHttpRequest Object</h2>

<p>The getResponseHeader() function is used to return specific


header information from a resource, like length, server-type,
content-type, last-modified, etc:</p>
<p>Last modified: <span id="demo"></span></p>
<script>
var xhttp=new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.getResponseHeader("Last-Modified");
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
</script>

</body>
</html>

JSON Make a table based on the value of a drop down menu.

<!DOCTYPE html>
<html>
<body>

<h2>Make a table based on the value of a drop down menu.</h2>

<select id="myselect" onchange="change_myselect(this.value)">


<option value="">Choose an option:</option>
<option value="customers">Customers</option>
<option value="products">Products</option>
<option value="suppliers">Suppliers</option>
</select>

<p id="demo"></p>

<script>
function change_myselect(sel) {
var obj, dbParam, xmlhttp, myObj, x, txt = "";
obj = { table: sel, limit: 20 };
dbParam = JSON.stringify(obj);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
txt += "<table border='1'>"
for (x in myObj) {
txt += "<tr><td>" + myObj[x].name + "</td></tr>";
}
txt += "</table>"
document.getElementById("demo").innerHTML = txt;
}
};
xmlhttp.open("POST", "json_demo_html_table.php", true);
xmlhttp.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
xmlhttp.send("x=" + dbParam);
}
</script>

</body>
</html>

Looping

Nested Arrays in JSON Objects

Values in an array can also be another array, or even another JSON


object:

<!DOCTYPE html>

<html>

<body>

<p>Looping through arrays inside arrays.</p>

<p id="demo"></p>

<script>
var myObj, i, j, x = "";

myObj = {

"name":"John",

"age":30,

"cars": [

{"name":"Ford", "models":["Fiesta", "Focus", "Mustang"]},

{"name":"BMW", "models":["320", "X3", "X5"]},

{"name":"Fiat", "models":["500", "Panda"] }

for (i in myObj.cars) {

x += "<h2>" + myObj.cars[i].name + "</h2>";

for (j in myObj.cars[i].models) {

x += myObj.cars[i].models[j] + "<br>";

document.getElementById("demo").innerHTML = x;

</script>

</body>

</html>
Email validation

<script​ ​type​ ​=​ ​"text/javascript"​>

​<!--

​function​ validateEmail​()​ ​{

​var​ emailID ​=​ document​.​myForm​.​EMail​.​value​;

atpos ​=​ emailID​.​indexOf​(​"@"​);

dotpos ​=​ emailID​.​lastIndexOf​(​"."​);

​if​ ​(​atpos ​<​ ​1​ ​||​ ​(​ dotpos ​-​ atpos ​<​ ​2​ ​))​ ​{

alert​(​"Please enter correct email ID"​)

document​.​myForm​.​EMail​.​focus​()​ ​;

​return​ ​false​;

​}

​return​(​ ​true​ ​);

​}

​//-->

</script>

Basic Validation

<html>

<head>

<title>Form Validation</title>
<script type = "text/javascript">

<!--

// Form validation code will come here.

//-->

</script>

</head>

<body>

<form action = "/cgi-bin/test.cgi" name = "myForm" onsubmit


= "return(validate());">

<table cellspacing = "2" cellpadding = "2" border = "1">

<tr>

<td align = "right">Name</td>

<td><input type = "text" name = "Name" /></td>

</tr>

<tr>

<td align = "right">EMail</td>

<td><input type = "text" name = "EMail" /></td>


</tr>

<tr>

<td align = "right">Zip Code</td>

<td><input type = "text" name = "Zip" /></td>

</tr>

<tr>

<td align = "right">Country</td>

<td>

<select name = "Country">

<option value = "-1" selected>[choose


yours]</option>

<option value = "1">USA</option>

<option value = "2">UK</option>

<option value = "3">INDIA</option>

</select>

</td>

</tr>

<tr>

<td align = "right"></td>

<td><input type = "submit" value = "Submit" /></td>


</tr>

</table>

</form>

</body>

</html>

JS validation

<script​ ​type​ ​=​ ​"text/javascript"​>

​<!--

​// Form validation code will come here.

​function​ validate​()​ ​{

​if​(​ document​.​myForm​.​Name​.​value ​==​ ​""​ ​)​ ​{

alert​(​ ​"Please provide your name!"​ ​);

document​.​myForm​.​Name​.​focus​()​ ​;

​return​ ​false​;

​}

​if​(​ document​.​myForm​.​EMail​.​value ​==​ ​""​ ​)​ ​{

alert​(​ ​"Please provide your Email!"​ ​);

document​.​myForm​.​EMail​.​focus​()​ ​;

​return​ ​false​;

​}
​ f​(​ document​.​myForm​.​Zip​.​value ​==​ ​""​ ​||​ isNaN​(
i
document​.​myForm​.​Zip​.​value ​)​ ​||

document​.​myForm​.​Zip​.​value​.​length ​!=​ ​5​ ​)​ ​{

alert​(​ ​"Please provide a zip in the format #####."


);

document​.​myForm​.​Zip​.​focus​()​ ​;

​return​ ​false​;

​}

​if​(​ document​.​myForm​.​Country​.​value ​==​ ​"-1"​ ​)​ ​{

alert​(​ ​"Please provide your country!"​ ​);

​return​ ​false​;

​}

​return​(​ ​true​ ​);

​}

​//-->

</script>

You might also like