Commit e8aea637 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
9780596521882
\ No newline at end of file
## Example files for the title:
# Learning JavaScript 2nd Edition, by Shelley Powers
[![Learning JavaScript 2nd Edition, by Shelley Powers](http://akamaicovers.oreilly.com/images/9780596521875/cat.gif)](https://www.safaribooksonline.com/library/view/title/9780596155636//)
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
alert("Hello, World!");
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function hello() {
// say hello to the world
var msg = "Hello, World!";
document.open();
document.write(msg);
document.close();
}
</script>
</head>
<body onload="hello()">
<p>Hi</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function hello() {
// say hello to the world
var msg = "Hello, <em>World!</em>";
document.open();
document.write(msg);
document.close();
}
//]]>
</script>
</head>
<body onload="hello()">
<p>Hi</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function hello() {
alert(window.navigator.cookieEnabled);
}
//]]>
</script>
</head>
<body onload="hello()">
<h1 id="pageHeader">
Hello there
</h1>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="helloworld.js">
</script>
</head>
<body onload="hello()">
<p>Hi</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function hello() {
// say hello to the world
var msg = "Hello, <em>World!</em>";
document.open();
document.write(msg);
document.close();
}
//]]>
</script>
</head>
<body onload="hello()">
<noscript>
<p>I'm still here, World!</p>
</noscript>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>URI Encoding</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function encodeStrings() {
var sOne = encodeURIComponent("http://burningbird.net/index.php?pagename=$1&page=$2");
var sTwo = encodeURI("http://someapplication.com/?catsname=Zöe&URL=");
var sOutput = "<p>Link is " + sTwo + sOne + "</p>";
document.write(sOutput);
var sOneDecoded = decodeURI(sTwo);
var sTwoDecoded = decodeURIComponent(sOne);
var sOutputDecoded = "<p>" + sOneDecoded + "</p><p>" + sTwoDecoded + "</p>";
document.write(sOutputDecoded);
}
//]]>
</script>
</head>
<body onload="encodeStrings()">
<p></p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Implicit and Explicit String Conversion</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function convertToString() {
var newNumber = 34.56;
var newBoolean = true;
var nothing;
var newNull = null;
var strNumber = String(newNumber); var strBoolean = String(newBoolean);
var strUndefined = String(nothing); var strNull = String(newNull);
var strOutput = "<p>" + strNumber + " " + strBoolean + " " + strUndefined + " " + strNull + "</p>";
document.writeln(strOutput);
var strOutput2 = String(document);
document.writeln(strOutput2);
}
//]]>
</script>
</head>
<body onload="convertToString()">
<p></p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Convert to Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function convertToNumber() {
var sNum = "1.23e-2";
document.writeln("<p>" + parseFloat(sNum) + "</p>");
document.writeln("<p>" + parseInt(sNum) + "</p>");
var fValue = parseFloat("1.45 inch");
document.writeln("<p>" + fValue + "</p>");
var iValue = parseInt("-33.50");
document.writeln("<p>" + iValue + "</p>");
}
//]]>
</script>
</head>
<body onload="convertToNumber()">
<p></p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Convert to Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function convertToNumber() {
var sNum = "1.23e-2";
document.writeln("<p>" + parseFloat(sNum) + "</p>");
var fValue = parseFloat("1.45 inch");
document.writeln("<p>" + fValue + "</p>");
}
//]]>
</script>
</head>
<body onload="convertToNumber()">
<p></p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Nested Conditional Statements</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function choices() {
var prefChoice = 1;
var stateChoice = 'OR';
var genderChoice = 'F';
if (prefChoice === 1) {
alert("You've picked option 1. Here is what will happen...");
if (stateChoice === 'OR') {
alert ("You've picked 1 and you're from Oregon.");
if (genderChoice === 'M') {
alert("You've picked 1 and you're from Oregon and you're a man.");
} // innermost block
} // middle block
} // outerblock
}
//]]>
</script>
</head>
<body onload="choices()">
<p>Imagine a form with five fields and a button here...</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>if...else</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function choices() {
var stateCode = 'MO';
var taxPercentage = 0.0;
if (stateCode === 'OR') {
taxPercentage = 3.5;
} else if (stateCode === 'CA') {
taxPercentage = 5.0;
} else if (stateCode === 'MO') {
taxPercentage = 1.0;
} else {
taxPercentage = 2.0;
}
alert(taxPercentage);
}
//]]>
</script>
</head>
<body onload="choices()">
<p>Imagine a form with options to pick state code</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>switch</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function choices() {
var stateCode = 'MO';
var statePercentage = 0.0;
var taxPercentage = 0.0;
switch (stateCode) {
case 'OR':
case 'MA':
case 'WI' :
statePercentage = 0.5;
taxPercentage = 3.5;
break;
case 'MO' :
taxPercentage = 1.0;
statePercentage = 1.5;
case 'CA' :
case 'NY' :
case 'VT' :
statePercentage = 2.6;
taxPercentage = 4.5;
break;
case 'TX' :
taxPercentage = 3.0;
break;
default :
taxPercentage = 2.0;
statePercentage = 2.3;
}
alert("tax is " + taxPercentage + " and state is " + statePercentage);
}
//]]>
</script>
</head>
<body onload="choices()">
<p>Imagine a form with options to pick state code</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Equality</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function choices() {
var sValue = "3.0";
var nValue = 3.0;
if (nValue == "3.0") alert("According to equality, value is 3.0");
if (nValue === "3.0") alert("According to strict equality, value is 3.0");
if (sValue != 3.0) alert ("According to equality, value is not 3.0");
if (sValue !== 3.0) alert ("According to strict equality, value is not 3.0");
}
//]]>
</script>
</head>
<body onload="choices()">
<p>Some page content</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Ranges of values</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function values() {
var nValue = 0;
if (nValue >= 0 && nValue <= 100) {
alert("value between 0 and 100, inclusive");
}
if (nValue > 0 && nValue < 100) {
alert("value between 0 and 100 exclusive");
}
if (nValue > 100) {
alert ("value over 100");
}
if (nValue < 0) {
alert ("value is negative");
}
}
//]]>
</script>
</head>
<body onload="values()">
<p>Some page content</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>while loop</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function loops() {
var strValue = "";
var nValue = 1;
while (nValue <= 10) {
strValue+=nValue;
nValue++;
}
alert(strValue);
}
//]]>
</script>
</head>
<body onload="loops()">
<p>Some page content</p>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment