Skip to main content

Posts

Showing posts with the label Javascript

Dynamic Welcome Page in JavaScript

To create a dynamic welcome page that obtains the  user's name, then diplays it on the page. The script uses another predefined dialog box from window object(a prompt dialog) which allows the user to input a value that the script can use. The program asks the user to input a name, then displays the name in the XHTML document. <html>   <head>     <title>Using Prompt and Alert Boxes</title>     <script type = "text/javascript">       <!--       var name; //string entered by the user           name = window.prompt( "Please enter your name" );           document.writeln( "<h1> Hello, " + name + ",               welcome to JavaScript programming!</h1>" );       // -->     </script>   </head>   <body>     <p>Click Re...

Escape Sequence and Descriptions

\n --- New Line. Position the screen cursor at the beginning of the next line. \t --- Horizontal tab. Move the screen cursor to the next tab stop. \r --- Cariage button. Position the screen cursor to the beginning of the current line; do not advance to the next line. Any characters output after the carriage return overwrite the characters previously output on that line. \\ --- Backslash. Used to represent a backslash character in a string. \" --- Double quote. Used to represent a double-quote character in a string contained in double quotes. \' --- single quote. Used to represent  a single-quote character in a string.

Displaying Text in an Alert Dialog

In JavaScript we can display information in windows called dialogs (or dialog boxes) that "pop up" on the screen to grab the user's attention. Dialogs typically diplay important messages to users browing the web page. JavaScript allows you easily to display a dialog box containing a message. The following program displays Welcome to JavaScript Programming! as three lines in a predefined dialog called an alert dialog. Alert dialog box displaying multiple lines. <html>   <head>     <title>Printing Multiple Lines in Dialog Box</title>     <script type = "text/javascript">       <!--       window.alert( "Welcome to \n JavaScript\nProgramming!" );       // -->     </script>   </head>   <body>     <p>Click Refresh to run this script again.</p>   </body> </html> The script user the browser's ...

Simple Program: Displaying a Line of Text in a Web Page

JavaScript uses notations, javascript may appear strange to non-programmers. We begin by considering a simple script that dispalys the text "Welcome to JavaScript Programming!" in the body of an XHTML document. All major web browsers contains JavaScript interpreters, which process the commands written in JavaScript. The JavaScript code we write will appear in the <head> section. The browser interprets the contents of the <head> section first, so the JavaScript programs we write there execute before the <body> of the XHTML document displays. Displaying a Line of Text <html>   <head>     <title>A First Program in JavaScript</title>     <script type = "text/javascript">       <!--       document.writeln( "<h1>Welcome to JavaScript Programming!</h1>" );       // -->     </script>   </head>   <body> ...