06_Javascript CSS
06_Javascript CSS
January 2020
Introduction
<script> and </script> tells where the JavaScript starts and ends.
<html>
<body>
<h1>My First Web Page</h1>
<p id="demo">This is a paragraph.</p>
<script type="text/javascript">
</script>
</body>
</html>
Common HTML Events
<!DOCTYPE html>
<html><head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "changed.";
}
</script>
</head>
<body>
<h1>A Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try</button>
</body>
</html>
JavaScript Popup Boxes
Alert Box - An alert box is often used if you want to make sure
information comes through to the user.
alert("I am an alert box!");
Confirm Box - A confirm box is often used if you want the user
to verify or accept something.
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
Prompt Box - A prompt box is often used if you want the user
to input a value before entering a page.
var person = prompt("Please enter your name", "Harry Potter");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
} else {
txt = "Hello " + person + "! How are you today?";
}
JavaScript Timing Events
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function validate() {
if (document.getElementById("txtName").value == "") {
return false;
}
else {
return true;
}
}
</script>
</head>
<body>
<form onsubmit="return validate()">
Name: <input type="text" id="txtName" /><br/>
<input type="submit" value="SUBMIT" />
</form>
</body>
</html>
jQuery
$(".checkButton").click(() => {
if ($("#txtName").val() == "") {
alert('please fill all values');
return false;
}
else {
return true;
}
});
Cascading Style Sheets (CSS)
CSS syntax
How To Add CSS