JavaScript Variable:
• In Javascript variables can be created that can hold any type of data. First the variables should be declared for good programming style and it will be easy for Javascript interpreter to understand those variables. Variables can be declared using var commands.All the javascript statements are end with a semicolon;
Syntax:-
Var<variable name>=value;
• When a variable is declared within a function, it is called as local variable and can only be accessed within that function.
• If a variable is declared outside a function then it is called as global variable and can be accessed by all the functions inside the program.
• variable names are case sensitive.
JavaScript Dialog Boxes:
• Javascript has the ability to take user input and display small amount of texts to the user by using dialog boxes. These dialog boxes appear as a separate windows and their content depends on the information provided by the user. This content is independent of the text in the HTML page containing the Javascript script and doesnot affect the content of the page in anyway. Threee types of dialog boxes are there in Javascript.
• Alert box
> It can be used to direct small amounts of textual output to a browser’s window. The Javascript alert() method takes a string as an argument and displays an alert dialog box in the browser window when invoked by appropriate Javascript.
> It displays the string passed to the alert() method, as well as an “OK” button. User will have to click “OK” for further processing of Javascript and HTML program.
> It can be used to display a cautionary message or some information. For further instance:
A massage is displayed to the user when proper information is not found in the form.
An invalid output will come after calculation.
A warning that a service is not available on a given date/time.
Syntax:-
alert(“<message>”);
Example:-
alert(“ClickOK to continue”);
• Confirm box
> It provides a second type of dialog box called confirm dialog box. As its name implies, this dialog box serves as a technique for confirming user action.
> It displays the following information:
A pre-defined massage.
“OK” and “CANCEL” button.
> It displays the string passed to the confirm() method, as well as either an “OK” button or a “CANCEL” button. User will have to click either “OK” or “CANCEL” button for further processing of program.
Clicking on the OK button causes TRUE to be passed to the program which called the confirm dialog box.
Clicking on the CANCEL button causes FALSE to be passed to the program which called the confirm dialog box.
Syntax:-
Confirm(“<message>”);
Example:-
Confirm(“Are you sure you want to exit from current file”);
• Prompt box
> Javascript provides third type of dialog box called prompt dialog box to customize any web page output based on user input, which is what user interaction requires.The prompt() method instantiates the prompt dialog box which displays a specified message.
> It displays the following information:
Displays a predefined message.
Displays a textbox and accepts user input.
Displays the “OK” and the “CANCEL” button.
> User will have to click either “OK” or “CANCEL” button for further processing of program.
Clicking on the OK button causes the text typed inside the text box to be passed to the program environment.
Clicking on the CANCEL button causes a NULL value to be passed to the program environment.
Syntax:-
Prompt(“<Message>” , “<Default value>”);
Example:-
Prompt(“Enter your favorite color:”, “green”);
JavaScript Language:-
• Conditional statement
> if, if.. else, switch
• Loop
> for loop, while loop
• try...catch
• throw


LinkBack URL
About LinkBacks
Reply With Quote

LinkBacks Enabled by vBSEO
Bookmarks