O'Reilly logo

Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition by Robin Nixon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13 Answers

  1. To enclose JavaScript code, you use <script> and </script> tags.

  2. By default, JavaScript code will output to the part of the document in which it resides. If it’s in the head it will output to the head; if the body, then the body.

  3. You can include JavaScript code from other sources in your documents by either copying and pasting them or, more commonly, including them as part of a <script src='filename.js'> tag.

  4. The equivalent of the echo and print commands used in PHP is the JavaScript document.write function (or method).

  5. To create a comment in JavaScript, preface it with // for a single-line comment or surround it with /* and */ for a multiline comment.

  6. The JavaScript string concatenation operator is the + symbol.

  7. Within a JavaScript function, you can define a variable that has local scope by preceding it with the var keyword upon first assignment.

  8. To display the URL assigned to the link with an ID of thislink in all main browsers, you can use the two following commands:

    document.write(document.getElementById('thislink').href)
    document.write(thislink.href)
  9. The commands to change to the previous page in the browser’s history array are:

    history.back()
    history.go(-1)
  10. To replace the current document with the main page at the oreilly.com website, you could use the following command:

    document.location.href = 'http://oreilly.com'

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required