Skip to main content

Home/ Groups/ Learning Library
Sunny Jackson

JavaScript Popup Boxes - 0 views

  • JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
  • Alert Box An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed.
  • Syntax alert("sometext");
  • ...5 more annotations...
  • <script type="text/javascript"> function show_alert() { alert("I am an alert box!"); } </script>
  • Confirm Box A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false. Syntax confirm("sometext");
  • <script type="text/javascript"> function show_confirm() { var r=confirm("Press a button"); if (r==true)   {   alert("You pressed OK!");   } else   {   alert("You pressed Cancel!");   } } </script>
  • Prompt Box A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null. Syntax prompt("sometext","defaultvalue");
  • <script type="text/javascript"> function show_prompt() { var name=prompt("Please enter your name","Harry Potter"); if (name!=null && name!="")   {   document.write("Hello " + name + "! How are you today?");   } } </script>
Sunny Jackson

JavaScript Switch Statement - 0 views

  • The JavaScript Switch Statement Use the switch statement to select one of many blocks of code to be executed. Syntax switch(n) { case 1:   execute code block 1   break; case 2:   execute code block 2   break; default:   code to be executed if n is different from case 1 and 2 }
  • Use break to prevent the code from running into the next case automatically.
Sunny Jackson

JavaScript If...Else Statements - 0 views

  • Conditional statements are used to perform different actions based on different conditions.
  • if statement - use this statement to execute some code only if a specified condition is true
  • if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false
  • ...8 more annotations...
  • if...else if....else statement - use this statement to select one of many blocks of code to be executed
  • switch statement - use this statement to select one of many blocks of code to be executed
  • Use the if statement to execute some code only if a specified condition is true. Syntax if (condition)   {   code to be executed if condition is true   }
  • Note that if is written in lowercase letters. Using uppercase letters (IF) will generate a JavaScript error!
  • Notice that there is no ..else.. in this syntax. You tell the browser to execute some code only if the specified condition is true.
  • If...else Statement Use the if....else statement to execute some code if a condition is true and another code if the condition is not true.
  • Syntax if (condition)   {   code to be executed if condition is true   } else   {   code to be executed if condition is not true   }
  • If...else if...else Statement Use the if....else if...else statement to select one of several blocks of code to be executed. Syntax if (condition1)   {   code to be executed if condition1 is true   } else if (condition2)   {   code to be executed if condition2 is true   } else   {   code to be executed if condition1 and condition2 are not true   }
Sunny Jackson

JavaScript Comparison and Logical Operators - 0 views

  • Comparison operators can be used in conditional statements to compare values and take action depending on the result: if (age<18) document.write("Too young");
  • JavaScript also contains a conditional operator that assigns a value to a variable based on some condition. Syntax variablename=(condition)?value1:value2 
Sunny Jackson

JavaScript Operators - 0 views

  • = is used to assign values.
  • + is used to add values.
  • The + operator can also be used to add string variables or text values together.
  • ...3 more annotations...
  • To add two or more string variables together, use the + operator. txt1="What a very"; txt2="nice day"; txt3=txt1+txt2;
  • To add a space between the two strings, insert a space into one of the strings: txt1="What a very "; txt2="nice day"; txt3=txt1+txt2; or insert a space into the expression: txt1="What a very"; txt2="nice day"; txt3=txt1+" "+txt2;
  • If you add a number and a string, the result will be a string!
Sunny Jackson

JavaScript Functions - 0 views

  • A function will be executed by an event or by a call to the function.
  • To keep the browser from executing a script when the page loads, you can put your script into a function.
  • A function contains code that will be executed by an event or by a call to the function.
  • ...13 more annotations...
  • You may call a function from anywhere within a page (or even from other pages if the function is embedded in an external .js file).
  • Functions can be defined both in the <head> and in the <body> section of a document. However, to assure that a function is read/loaded by the browser before it is called, it could be wise to put functions in the <head> section.
  • How to Define a Function Syntax function functionname(var1,var2,...,varX) { some code }
  • The { and the } defines the start and end of the function.
  • The parameters var1, var2, etc. are variables or values passed into the function.
  • A function with no parameters must include the parentheses () after the function name.
  • The word function must be written in lowercase letters, otherwise a JavaScript error occurs!
  • Also note that you must call a function with the exact same capitals as in the function name.
  • The return Statement The return statement is used to specify the value that is returned from the function. So, functions that are going to return a value must use the return statement.
  • <script type="text/javascript"> function product(a,b) { return a*b; } </script>
  • If you declare a variable, using "var", within a function, the variable can only be accessed within that function. When you exit the function, the variable is destroyed. These variables are called local variables.
  • You can have local variables with the same name in different functions, because each is recognized only by the function in which it is declared.
  • If you declare a variable outside a function, all the functions on your page can access it. The lifetime of these variables starts when they are declared, and ends when the page is closed.
Sunny Jackson

JavaScript for Loop - 0 views

  • Loops execute a block of code a specified number of times, or while a specified condition is true.
  • In JavaScript, there are two different kind of loops: for - loops through a block of code a specified number of times while - loops through a block of code while a specified condition is true
  • The for Loop The for loop is used when you know in advance how many times the script should run. Syntax for (variable=startvalue;variable<=endvalue;variable=variable+increment) { code to be executed }
Sunny Jackson

JavaScript while Loop - 0 views

  • The while Loop The while loop loops through a block of code while a specified condition is true. Syntax while (variable<=endvalue)   {   code to be executed   }
  • The do...while Loop The do...while loop is a variant of the while loop. This loop will execute the block of code ONCE, and then it will repeat the loop as long as the specified condition is true. Syntax do   {   code to be executed   } while (variable<=endvalue);
Sunny Jackson

JavaScript Break and Continue Statements - 0 views

  • The break Statement The break statement will break the loop and continue executing the code that follows after the loop (if any).
  • <script type="text/javascript"> var i=0; for (i=0;i<=10;i++)   {   if (i==3)     {     break;     }   document.write("The number is " + i);   document.write("<br />");   } </script>
  • The continue Statement The continue statement will break the current loop and continue with the next value.
  • ...1 more annotation...
  • <script type="text/javascript"> var i=0 for (i=0;i<=10;i++)   {   if (i==3)     {     continue;     }   document.write("The number is " + i);   document.write("<br />");   } </script>
Sunny Jackson

JavaScript For...In Statement - 0 views

  • JavaScript For...In Statement The for...in statement loops through the elements of an array or through the properties of an object. Syntax for (variable in object)   {   code to be executed   }
  • The code in the body of the for...in loop is executed once for each element/property.
Sunny Jackson

JavaScript Guidelines - 0 views

  • JavaScript is case sensitive - therefore watch your capitalization closely when you create or call variables, objects and functions.
Sunny Jackson

JavaScript Special Characters - 0 views

  • In JavaScript you can add special characters to a text string by using the backslash sign.
  • Insert Special Characters The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.
  • In JavaScript, a string is started and stopped with either single or double quotes.
  • ...4 more annotations...
  • place a backslash (\) before each double quote
  • This turns each double quote into a string literal:
  • JavaScript will now output the proper text string
  • Code Outputs \' single quote \" double quote \\ backslash \n new line \r carriage return \t tab \b backspace \f form feed
Sunny Jackson

JavaScript Throw Statement - 0 views

  • The Throw Statement The throw statement allows you to create an exception. If you use this statement together with the try...catch statement, you can control program flow and generate accurate error messages. Syntax throw exception
  • throw is written in lowercase letters. Using uppercase letters will generate a JavaScript error!
Sunny Jackson

JavaScript Try...Catch Statement - 0 views

  • The try...catch statement allows you to test a block of code for errors.
  • The try...catch Statement The try...catch statement allows you to test a block of code for errors. The try block contains the code to be run, and the catch block contains the code to be executed if an error occurs. Syntax try   {   //Run some code here   } catch(err)   {   //Handle errors here   } Note that try...catch is written in lowercase letters. Using uppercase letters will generate a JavaScript error!
  • The throw Statement The throw statement can be used together with the try...catch statement, to create an exception for the error
Sunny Jackson

JavaScript Events - 0 views

  • Events are actions that can be detected by JavaScript.
  • Every element on a web page has certain events which can trigger a JavaScript. For example, we can use the onClick event of a button element to indicate that a function will run when a user clicks on the button. We define the events in the HTML tags.
  • Examples of events: A mouse click A web page or an image loading Mousing over a hot spot on the web page Selecting an input field in an HTML form Submitting an HTML form A keystroke
  • ...5 more annotations...
  • Events are normally used in combination with functions, and the function will not be executed before the event occurs!
  • The onLoad and onUnload events are triggered when the user enters or leaves the page.
  • The onFocus, onBlur and onChange events are often used in combination with validation of form fields
  • onSubmit The onSubmit event is used to validate ALL form fields before submitting it.
  • onMouseOver and onMouseOut are often used to create "animated" buttons.
Sunny Jackson

W3Schools' Certifications - 0 views

  • Online Certification Program
  • Study at no cost
  • Study when it is convenient
  • ...11 more annotations...
  • Study from your own computer
  • HTML Developer Certificate
  • CSS Developer Certificate
  • JavaScript Developer Certificate
  • jQuery Developer Certificate
  • XML Developer Certificate
  • ASP Developer Certificate
  • PHP Developer Certificate
  • Documentation of your skills enables you to move upwards
  • Getting a certificate proves your commitment to upgrade your skills, gives you the credibility needed for more responsibilities, larger projects, and a higher salary.
  • documented knowledge is often the key factor when hiring new personnel
Sunny Jackson

W3Schools Online Web Tutorials - 0 views

Sunny Jackson

CSS Text - 0 views

  • text-align:justify;
« First ‹ Previous 341 - 360 of 737 Next › Last »
Showing 20 items per page