Professional Documents
Culture Documents
<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>
<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>
<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>
</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>
<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>
<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>
<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>
</body>
</html>
JS Array
Change Element
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>
<input id="numb">
<p id="demo"></p>
<script>
function myFunction() {
var x, text;
<!DOCTYPE html>
<html>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>
<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>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<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
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var myObj, i, j, x = "";
myObj = {
"name":"John",
"age":30,
"cars": [
for (i in myObj.cars) {
for (j in myObj.cars[i].models) {
x += myObj.cars[i].models[j] + "<br>";
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
Email validation
<!--
function validateEmail() {
if (atpos < 1 || ( dotpos - atpos < 2 )) {
document.myForm.EMail.focus() ;
return false;
}
}
//-->
</script>
Basic Validation
<html>
<head>
<title>Form Validation</title>
<script type = "text/javascript">
<!--
//-->
</script>
</head>
<body>
<tr>
</tr>
<tr>
<tr>
</tr>
<tr>
<td>
</select>
</td>
</tr>
<tr>
</table>
</form>
</body>
</html>
JS validation
<!--
function validate() {
document.myForm.Name.focus() ;
return false;
}
document.myForm.EMail.focus() ;
return false;
}
f( document.myForm.Zip.value == "" || isNaN(
i
document.myForm.Zip.value ) ||
document.myForm.Zip.focus() ;
return false;
}
return false;
}
}
//-->
</script>