References Used


History


Uses and Limitations


JavaScript Terminology


Embedding JavaScript in an HTML Page


Debugging JavaScript


Variables, Operators, and Expressions


Comments


Input and Output

  • Input can be obtained in one of two ways:

    1. via form elements (to be discussed later)
    2. via the prompt function

      1. the prompt function pops up a dialog box with a text box and allows the user to enter a string of input
      2. the prompt function returns the string as its return value
      3. syntax: prompt("prompt message", default value)
      4. example: prompt("please enter sales tax rate", ".05");
      5. it is ok to provide an empty string, '', as the default value, or to simply omit the default value, in which case it will default to the empty string
      6. it is ok to provide any evaluable expression as the default value--the resulting value will be converted to a string
      7. if the user presses the "Cancel" button then prompt returns null
  • Output can be provided in a number of ways

    1. document.write(string): document is a pre-defined object and write is a method that writes a string. You use the write method to dynamically create content on a web-page as it it being loaded.
      1. You can use the string concatenation operator, +, to concatenate several string fragments.

      2. You can write html markup in order to obtain formatted output.

      3. write destroys the content that was previously displayed on the web page so do not use it after the html page has loaded. Once the html page has loaded, you should modify the page by adding or deleting nodes from the dom tree (talked about in the AJAX notes).

      4. document.writeln will write a string with a newline attached to it but it is of limited utility because 1) the newline does not show up in the html output--<br> would be needed to do that, and 2) the source view will show the script, not the dynamically generated html so the string will not show up in the source view.

    2. alert(string): alert will pop up a dialog box with the given string value. Execution of the script will be suspended until the user presses the ok button.

    3. alter the html dom: You can use javascript to modify, add, or delete nodes from the html dom, and this will adjust the contents of the page. We will discuss the html dom in later notes.

    Ifs and Loops