Category: JavaScript

JavaScript

Ok Cancel prompt javaScript

Ok Cancel prompt javaScript

This dialog box is displayed using a method called prompt() which takes two parameters (i) A label which you want to display in the text box (ii) A default string to display in the...

Ajax with php

Ajax with php

With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using...

Redirect page in jQuery/JavaScript

Redirect page in jQuery/JavaScript

jQuery is not necessary, and window.location.replace(…) will best simulate an HTTP redirect.   It is better than using window.location.href =, because replace() does not put the originating page in the session history, meaning the...

Explicit Casting

Explicit Casting

Unlike PHP, JavaScript has no explicit casting of types such as (int) or (float). Instead, when you need a value to be of a certain type, use one of JavaScript’s built-in functions, shown in...

The continue Statement

The continue Statement

Sometimes you don’t want to entirely exit from a loop, but instead wish to skip the remaining statements just for this iteration of the loop. In such cases, you can use the continue command....

Breaking Out of a Loop

Breaking Out of a Loop

The break command, which you saw to be important inside a switch statement, is also available within for loops. You might need to use this, for example, when searching for a match of some...

for Loops

for Loops

A for loop combines the best of all worlds into a single looping construct that allows you to pass three parameters for each statement: • An initialization expression • A condition expression • A...

do while Loops

do while Loops

When you require a loop to iterate at least once before any tests are made, use a do…while loop, which is similar to a while loop, except that the test expression is checked only...

while Loops

while Loops

A JavaScript while loop first checks the value of an expression and starts executing the statements within the loop only if that expression is true. If it is false, execution skips over to the...

The switch Statement

The switch Statement

The switch statement is useful when one variable or the result of an expression can have multiple values, for each of which you want to perform a different function. The variable page is mentioned...

The if Statement

The if Statement

Several examples in these tutorials have already made use of if statements. The code within such a statement is executed only if the given expression evaluates to true. Multiline if statements require curly braces...