JavaScript events allow code to run in response to user actions or changes to the document. Common events include onclick which fires when the user clicks an element, and onload which fires when a page finishes loading. JavaScript code is associated with events using HTML event handler attributes or by registering event listeners in the code. Events help make pages dynamic and interactive by triggering JavaScript functions in response to user input.
JavaScript is a scripting language that can be used to make web pages interactive. It allows you to check and modify HTML forms, change images, and write dynamic content. JavaScript code is executed by the browser and only affects the current page. The language is case sensitive, lightweight, and interpreted rather than compiled. Variables, literals, objects, operators, control structures, and functions are the basic components of JavaScript code. Comments can be added to explain code. JavaScript code can be embedded directly in HTML pages or linked via external .js files. Code placement in the head or body affects when it runs.
This document provides an introduction to JavaScript. It defines JavaScript as a lightweight, interpreted programming language that allows adding interactivity to HTML pages. Some key points covered include:
- JavaScript advantages like less server interaction and immediate feedback.
- JavaScript limitations like not allowing file reading/writing.
- The Document Object Model (DOM) represents the HTML document when loaded into a browser as a document object that provides access to all node objects.
- Common JavaScript operators, conditional statements, and built-in objects like Math, Date, String, and Window are described. Form validation using JavaScript is also discussed.
The document provides information on JavaScript fundamentals including:
- JavaScript is an object-oriented scripting language used to make web pages interactive. It was originally called LiveScript and developed by Netscape.
- JavaScript can be used for both client-side scripting in web browsers and server-side scripting using Node.js. It is an interpreted language that is loosely typed, prototype-based, and supports operators, control structures, and functions.
- Common uses of JavaScript include form validation, dynamic updating of content, and basic interactivity on web pages. It works with HTML and CSS to create dynamic web pages.
JavaScript is the primary scripting language of the web and is used to make web pages interactive. It can dynamically write and modify HTML content, react to user events like clicks, validate form data, detect the browser, and more. JavaScript code is commonly embedded directly in HTML using <script> tags and can also be stored externally in .js files. Key JavaScript concepts include variables, operators, conditional statements, functions, loops, and events.
JavaScript is a scripting language that adds interactivity to HTML pages. It can be used to dynamically write text, react to events, read and write HTML elements, validate data, detect the visitor's browser, and create cookies. JavaScript code can be placed in the head or body sections of an HTML page and is usually embedded directly into HTML pages. External JavaScript files can also be used to run the same code on multiple pages.
JavaScript is the most popular scripting language used on web pages. It can be used to add interactivity and dynamic content to HTML pages. JavaScript code can be embedded directly in HTML pages or stored externally in .js files. JavaScript code can be placed in the <head> or <body> sections of an HTML page. Common JavaScript statements include conditional statements like if/else, loops like for and while loops, and functions. JavaScript also provides popup boxes like alert, confirm, and prompt to interact with users.
The document provides an overview of JavaScript including its history, uses, and how to implement it. Some key points covered include:
- JavaScript was originally created by Netscape under the names Mocha and LiveScript, and is now known as ECMAScript. It is an interpreted scripting language that can be added to HTML pages or linked via external files.
- JavaScript can be used to make web pages more dynamic by manipulating HTML objects, validating forms, detecting browsers, and handling events. It runs in the browser rather than on the server.
- The document discusses different ways of implementing JavaScript including embedding it directly in HTML, linking external .js files, and issues around browser compatibility.
-
Java Script is an interpreted programming language commonly used to create interactive effects within web browsers. It is embedded into HTML and allows for interaction and validation of user data on websites. Java Script code can be placed within <script> tags in the head or body section of an HTML document or linked via an external .js file for code reuse across pages.
JavaScript is a scripting language that can be used to make web pages interactive. It allows you to check and modify HTML forms, change images, and write dynamic content. JavaScript code is executed by the browser and only affects the current page. The language is case sensitive, lightweight, and interpreted rather than compiled. Variables, literals, objects, operators, control structures, and functions are the basic components of JavaScript code. Comments can be added to explain code. JavaScript code can be embedded directly in HTML pages or linked via external .js files. Code placement in the head or body affects when it runs.
This document provides an introduction to JavaScript. It defines JavaScript as a lightweight, interpreted programming language that allows adding interactivity to HTML pages. Some key points covered include:
- JavaScript advantages like less server interaction and immediate feedback.
- JavaScript limitations like not allowing file reading/writing.
- The Document Object Model (DOM) represents the HTML document when loaded into a browser as a document object that provides access to all node objects.
- Common JavaScript operators, conditional statements, and built-in objects like Math, Date, String, and Window are described. Form validation using JavaScript is also discussed.
The document provides information on JavaScript fundamentals including:
- JavaScript is an object-oriented scripting language used to make web pages interactive. It was originally called LiveScript and developed by Netscape.
- JavaScript can be used for both client-side scripting in web browsers and server-side scripting using Node.js. It is an interpreted language that is loosely typed, prototype-based, and supports operators, control structures, and functions.
- Common uses of JavaScript include form validation, dynamic updating of content, and basic interactivity on web pages. It works with HTML and CSS to create dynamic web pages.
JavaScript is the primary scripting language of the web and is used to make web pages interactive. It can dynamically write and modify HTML content, react to user events like clicks, validate form data, detect the browser, and more. JavaScript code is commonly embedded directly in HTML using <script> tags and can also be stored externally in .js files. Key JavaScript concepts include variables, operators, conditional statements, functions, loops, and events.
JavaScript is a scripting language that adds interactivity to HTML pages. It can be used to dynamically write text, react to events, read and write HTML elements, validate data, detect the visitor's browser, and create cookies. JavaScript code can be placed in the head or body sections of an HTML page and is usually embedded directly into HTML pages. External JavaScript files can also be used to run the same code on multiple pages.
JavaScript is the most popular scripting language used on web pages. It can be used to add interactivity and dynamic content to HTML pages. JavaScript code can be embedded directly in HTML pages or stored externally in .js files. JavaScript code can be placed in the <head> or <body> sections of an HTML page. Common JavaScript statements include conditional statements like if/else, loops like for and while loops, and functions. JavaScript also provides popup boxes like alert, confirm, and prompt to interact with users.
The document provides an overview of JavaScript including its history, uses, and how to implement it. Some key points covered include:
- JavaScript was originally created by Netscape under the names Mocha and LiveScript, and is now known as ECMAScript. It is an interpreted scripting language that can be added to HTML pages or linked via external files.
- JavaScript can be used to make web pages more dynamic by manipulating HTML objects, validating forms, detecting browsers, and handling events. It runs in the browser rather than on the server.
- The document discusses different ways of implementing JavaScript including embedding it directly in HTML, linking external .js files, and issues around browser compatibility.
-
Java Script is an interpreted programming language commonly used to create interactive effects within web browsers. It is embedded into HTML and allows for interaction and validation of user data on websites. Java Script code can be placed within <script> tags in the head or body section of an HTML document or linked via an external .js file for code reuse across pages.
Java Script is one of the most pervasive languages found on the internet and World Wide Web. Java Script is useful in making web pages more interactive. The pages can be made to react to the actions of the users in the form of special effects, both visual and otherwise.
This document provides an introduction and overview of JavaScript. It discusses that JavaScript is a client-side scripting language that can be inserted into HTML pages and run by web browsers to provide interactive and dynamic features. It covers JavaScript basics like data types, variables, operators, functions, and events. It also explains how to write JavaScript code directly in HTML pages or externally and shows examples of built-in functions and how to create user-defined functions.
JavaScript is a scripting language that enhances functionality and appearance of web pages. It allows pages to be more dynamic and interactive through features like form validation, cookies, and animations. JavaScript code is embedded directly into HTML and runs in web browsers and other environments. A basic JavaScript program prints text to a web page. It uses <script> tags to indicate JavaScript code and document.writeln() to output text. User input can be obtained through prompts, which pop up dialog boxes. Variables are used to store and work with input data. The code examples demonstrate basic output and input methods in JavaScript.
JavaScript was originally named Mocha but was renamed LiveScript and then JavaScript. It is a lightweight, interpreted programming language designed for creating network-centric and browser-based applications. JavaScript can be used for client-side scripting through features like popup boxes and event handling, and for server-side scripting by running JavaScript code on the server with Node.js. It includes basic datatypes, operators, control flows, and built-in objects for manipulating the browser and its DOM.
JavaScript is a scripting language that allows adding interactivity to HTML pages. It can be used for client-side form validation and integration with user plugins. JavaScript is case-sensitive and allows variables, functions, conditional statements, and objects. Common uses include pop-up boxes, event handling, and cookies.
This document provides an overview of JavaScript including:
- JavaScript is an interpreted programming language that allows adding interactivity to HTML pages.
- It is commonly used for client-side scripting of web pages in browsers.
- Core JavaScript concepts like variables, data types, operators, and functions are introduced.
- Different types of loops in JavaScript like for, for/in, while and do/while loops are explained.
- Best practices for including JavaScript code in HTML files using <script> tags are covered.
JavaScript is a scripting language that adds interactivity to HTML pages. It works in all major browsers and is used to build dynamic web pages. JavaScript can react to events, modify HTML elements, validate forms, detect browsers, and write cookies. It is commonly placed in <script> tags within HTML pages or linked via external .js files. Comments are added to explain JavaScript code and prevent execution.
This document provides an overview of JavaScript fundamentals including a brief history of JavaScript, its uses, language features, inclusion of scripts in HTML documents, and the JavaScript object model. It discusses the window object and properties like location, frames, history. It also covers variables and data types, operators, control structures, arrays, functions, and communicating with the user through prompts, alerts and changing the status bar.
JavaScript allows for interactivity on web pages by manipulating HTML elements and reacting to user actions. It is a scripting language that runs in web browsers and is used to validate form input, detect browsers, and create dynamic content. JavaScript code is embedded within HTML pages and works together with HTML for content and CSS for presentation.
JavaScript is a scripting language that allows dynamic interactivity on web pages. It was invented by Brendan Eich and can be used to create image galleries, layout changes, and button click responses. JavaScript code can be placed between <script> tags in HTML documents or in external .js files. Some key features include client-side execution in web browsers, dynamic rendering variations across browsers, and potential security issues if not implemented carefully. Common uses of JavaScript include manipulating DOM elements, handling events, and validating forms.
Over 200 Pages of resources and code snippets to learn JavaScript and JavaScript DOM manipulation. JavaScript is the most popular web programming language and this eBook will help you learn more about JavaScript Coding
JavaScript is a client-side scripting language that allows web pages to become interactive and dynamic. It can update and modify the content of an HTML page without needing to reload the page. JavaScript code can be embedded directly in HTML pages or placed in separate .js files. Common uses of JavaScript include validating form input, detecting the visitor's browser, creating cookies, and adding interactivity to HTML elements like buttons and links.
JavaScript is a programming language used to make web pages interactive. It can be placed in the <body> and <head> sections of an HTML page. JavaScript code must be inserted between <script> and </script> tags. Functions and events allow JavaScript code to run when events occur, like when a user clicks a button. Scripts can also be placed in external .js files for reuse across pages. JavaScript can output data through alerts, writing to the HTML, or the browser console. Variables are used to store and work with data in JavaScript programs. Comments are used to explain code and prevent execution when needed.
This document provides an introduction and overview of JavaScript. It includes examples of basic JavaScript programs that change HTML content, attribute values, and styles. It discusses advantages of placing scripts in external files and defines key JavaScript concepts like comments, case sensitivity, data types, variables and literals. The document serves as a tutorial for beginners to learn JavaScript fundamentals.
This article is the first part of a series of articles on using JavaScript tools. Today, JavaScript is a very powerful language that can be used to build web apps, mobile apps, and even some pc games — perhaps a bit faster than you would build them otherwise.
New libraries have emerged in the web industry to address the challenges of JavaScript — libraries such as JQuery, Prototype and many others have been released. Today, a popular question asked by many is — should i learn the libraries such as jQuery or learn basic JavaScript. The truth is that the libraries help you to create faster, responsive JavaScript, but there are still times when your basic knowlege of JavaScript will be called into question. It is for this reason that I have created this eBook, to assist newbies learn JavaScript.
JavaScript can be used for client-side scripting to add interactivity to web pages. The client-side environment where JavaScript runs is usually a web browser. JavaScript code is transferred from the web server to the user's computer and run directly in the browser. Common uses of JavaScript include adding multimedia elements to pages, creating pages dynamically based on user input, and allowing interaction through events like clicking buttons.
Javascript is a dynamic programming language used primarily for client-side web page scripting. It allows for less server interaction, immediate feedback, and richer interfaces. Key differences from Java include being lightweight, interpreted, and lacking features like file access, networking, or multithreading. Javascript code is placed within <script> tags and can be used to dynamically manipulate and interact with HTML pages.
JavaScript can change HTML content, attributes, styles, and validate data. It can be placed in the <body> and <head> sections between <script> tags. Functions and events allow JavaScript code to run when events occur. JavaScript can output to alerts, the document, elements, and the console. It uses data types like numbers, strings, Booleans, arrays, and objects. Conditionals like if/else and switch statements allow different code blocks to run based on conditions. Loops like for, for/in, while, and do/while repeat code.
This document provides information on JavaScript terms and rules to remember for reading in user input and displaying output. It includes definitions of terms like alert(), prompt(), parseFloat(), and document.write(). It also provides code examples of using parseFloat() and document.write() to display numeric values. Finally, it includes exercises asking the reader to write JavaScript code to calculate work done and density, as well as to prompt for and display user data.
The document provides an overview of IP telephony protocols and architectures. It discusses how telecommunications are undergoing radical changes with the rise of IP telephony. It then summarizes the key components and standards of IP telephony systems, including H.323, an umbrella standard for multimedia conferencing produced by the ITU. H.323 defines protocols for call signaling (H.225), media stream packetization (H.245), and registration, admission and status (RAS) signaling.
Java Script is one of the most pervasive languages found on the internet and World Wide Web. Java Script is useful in making web pages more interactive. The pages can be made to react to the actions of the users in the form of special effects, both visual and otherwise.
This document provides an introduction and overview of JavaScript. It discusses that JavaScript is a client-side scripting language that can be inserted into HTML pages and run by web browsers to provide interactive and dynamic features. It covers JavaScript basics like data types, variables, operators, functions, and events. It also explains how to write JavaScript code directly in HTML pages or externally and shows examples of built-in functions and how to create user-defined functions.
JavaScript is a scripting language that enhances functionality and appearance of web pages. It allows pages to be more dynamic and interactive through features like form validation, cookies, and animations. JavaScript code is embedded directly into HTML and runs in web browsers and other environments. A basic JavaScript program prints text to a web page. It uses <script> tags to indicate JavaScript code and document.writeln() to output text. User input can be obtained through prompts, which pop up dialog boxes. Variables are used to store and work with input data. The code examples demonstrate basic output and input methods in JavaScript.
JavaScript was originally named Mocha but was renamed LiveScript and then JavaScript. It is a lightweight, interpreted programming language designed for creating network-centric and browser-based applications. JavaScript can be used for client-side scripting through features like popup boxes and event handling, and for server-side scripting by running JavaScript code on the server with Node.js. It includes basic datatypes, operators, control flows, and built-in objects for manipulating the browser and its DOM.
JavaScript is a scripting language that allows adding interactivity to HTML pages. It can be used for client-side form validation and integration with user plugins. JavaScript is case-sensitive and allows variables, functions, conditional statements, and objects. Common uses include pop-up boxes, event handling, and cookies.
This document provides an overview of JavaScript including:
- JavaScript is an interpreted programming language that allows adding interactivity to HTML pages.
- It is commonly used for client-side scripting of web pages in browsers.
- Core JavaScript concepts like variables, data types, operators, and functions are introduced.
- Different types of loops in JavaScript like for, for/in, while and do/while loops are explained.
- Best practices for including JavaScript code in HTML files using <script> tags are covered.
JavaScript is a scripting language that adds interactivity to HTML pages. It works in all major browsers and is used to build dynamic web pages. JavaScript can react to events, modify HTML elements, validate forms, detect browsers, and write cookies. It is commonly placed in <script> tags within HTML pages or linked via external .js files. Comments are added to explain JavaScript code and prevent execution.
This document provides an overview of JavaScript fundamentals including a brief history of JavaScript, its uses, language features, inclusion of scripts in HTML documents, and the JavaScript object model. It discusses the window object and properties like location, frames, history. It also covers variables and data types, operators, control structures, arrays, functions, and communicating with the user through prompts, alerts and changing the status bar.
JavaScript allows for interactivity on web pages by manipulating HTML elements and reacting to user actions. It is a scripting language that runs in web browsers and is used to validate form input, detect browsers, and create dynamic content. JavaScript code is embedded within HTML pages and works together with HTML for content and CSS for presentation.
JavaScript is a scripting language that allows dynamic interactivity on web pages. It was invented by Brendan Eich and can be used to create image galleries, layout changes, and button click responses. JavaScript code can be placed between <script> tags in HTML documents or in external .js files. Some key features include client-side execution in web browsers, dynamic rendering variations across browsers, and potential security issues if not implemented carefully. Common uses of JavaScript include manipulating DOM elements, handling events, and validating forms.
Over 200 Pages of resources and code snippets to learn JavaScript and JavaScript DOM manipulation. JavaScript is the most popular web programming language and this eBook will help you learn more about JavaScript Coding
JavaScript is a client-side scripting language that allows web pages to become interactive and dynamic. It can update and modify the content of an HTML page without needing to reload the page. JavaScript code can be embedded directly in HTML pages or placed in separate .js files. Common uses of JavaScript include validating form input, detecting the visitor's browser, creating cookies, and adding interactivity to HTML elements like buttons and links.
JavaScript is a programming language used to make web pages interactive. It can be placed in the <body> and <head> sections of an HTML page. JavaScript code must be inserted between <script> and </script> tags. Functions and events allow JavaScript code to run when events occur, like when a user clicks a button. Scripts can also be placed in external .js files for reuse across pages. JavaScript can output data through alerts, writing to the HTML, or the browser console. Variables are used to store and work with data in JavaScript programs. Comments are used to explain code and prevent execution when needed.
This document provides an introduction and overview of JavaScript. It includes examples of basic JavaScript programs that change HTML content, attribute values, and styles. It discusses advantages of placing scripts in external files and defines key JavaScript concepts like comments, case sensitivity, data types, variables and literals. The document serves as a tutorial for beginners to learn JavaScript fundamentals.
This article is the first part of a series of articles on using JavaScript tools. Today, JavaScript is a very powerful language that can be used to build web apps, mobile apps, and even some pc games — perhaps a bit faster than you would build them otherwise.
New libraries have emerged in the web industry to address the challenges of JavaScript — libraries such as JQuery, Prototype and many others have been released. Today, a popular question asked by many is — should i learn the libraries such as jQuery or learn basic JavaScript. The truth is that the libraries help you to create faster, responsive JavaScript, but there are still times when your basic knowlege of JavaScript will be called into question. It is for this reason that I have created this eBook, to assist newbies learn JavaScript.
JavaScript can be used for client-side scripting to add interactivity to web pages. The client-side environment where JavaScript runs is usually a web browser. JavaScript code is transferred from the web server to the user's computer and run directly in the browser. Common uses of JavaScript include adding multimedia elements to pages, creating pages dynamically based on user input, and allowing interaction through events like clicking buttons.
Javascript is a dynamic programming language used primarily for client-side web page scripting. It allows for less server interaction, immediate feedback, and richer interfaces. Key differences from Java include being lightweight, interpreted, and lacking features like file access, networking, or multithreading. Javascript code is placed within <script> tags and can be used to dynamically manipulate and interact with HTML pages.
JavaScript can change HTML content, attributes, styles, and validate data. It can be placed in the <body> and <head> sections between <script> tags. Functions and events allow JavaScript code to run when events occur. JavaScript can output to alerts, the document, elements, and the console. It uses data types like numbers, strings, Booleans, arrays, and objects. Conditionals like if/else and switch statements allow different code blocks to run based on conditions. Loops like for, for/in, while, and do/while repeat code.
This document provides information on JavaScript terms and rules to remember for reading in user input and displaying output. It includes definitions of terms like alert(), prompt(), parseFloat(), and document.write(). It also provides code examples of using parseFloat() and document.write() to display numeric values. Finally, it includes exercises asking the reader to write JavaScript code to calculate work done and density, as well as to prompt for and display user data.
The document provides an overview of IP telephony protocols and architectures. It discusses how telecommunications are undergoing radical changes with the rise of IP telephony. It then summarizes the key components and standards of IP telephony systems, including H.323, an umbrella standard for multimedia conferencing produced by the ITU. H.323 defines protocols for call signaling (H.225), media stream packetization (H.245), and registration, admission and status (RAS) signaling.
This presentation provides an overview of Hadoop, including what it is, how it works, its architecture and components, and examples of its use. Hadoop is an open-source software platform for distributed storage and processing of large datasets across clusters of computers. It allows for the reliable, scalable and distributed processing of large datasets through its core components - the Hadoop Distributed File System (HDFS) for storage, and MapReduce for processing.
Here is the code:
<script>
var x = 33;
var y = 10 + x;
alert(y);
</script>
Expected Result: 43
Explanation:
Variable x is assigned the value 33
Variable y performs the operation 10 + x (which is 33)
The result 43 is displayed in an alert box
This document outlines a lesson plan on spintronics. It includes measurable objectives for students to understand the differences between classic and quantum mechanics, learn about spintronics, define a qubit, compare conventional and spintronic devices, and design a future computer. The lesson will include discussions on computer technology past and present, introduce concepts of quantum mechanics and spintronics, explore commercial applications, and have students design and present a future computer system. Students will be evaluated on a demonstration of the objectives in a written report and presentation.
Some times we can forget that one of the most interesting uses of a language like Groovy is to make small scripts, beyond the need of playing with the rules and peculiarities of monster frameworks like Grails. This point is interesting not only for Groovy programmers, but also (specially) for Java programmers afraid of using Groovy in production code for being "dirty".
In this talk we'll see how Groovy is a language specially prepared for scripting, and very easy to handle for programmers with a Java background. We'll also explore some peculiarities of Groovy scripts in comparison to complete applications, and some interesting ideas which can be applied to scripts, based on my experience, and can be useful to anyone.
This document provides an overview of JavaScript basics including variables, data types, operators, conditional statements, loops, functions, arrays, and error handling. It explains JavaScript syntax, how to include JavaScript code in HTML pages, and commonly used statements like if/else, switch case, while and for loops. It also covers JavaScript functions, returning values from functions, and printing pages. The document describes JavaScript strings and array objects, and their associated methods. Finally, it discusses different types of errors in JavaScript like syntax errors, runtime errors, and logical errors.
JavaScript is a client-side scripting language that adds interactivity to web pages. It runs in the browser rather than on the server. JavaScript code can be added inline, internally, or externally. Common statements include document.write to output content, variables to store values, if/else conditions to check statements, and for/while loops to iterate. Functions allow code reuse. Operators like ==, >, && are used to compare values and check logic.
This document provides an overview of JavaScript concepts and features. It introduces JavaScript, its uses, basic syntax like variables, operators, and popup boxes. It also covers conditional statements, loops, functions, arrays, objects like Date and Math objects, regular expressions, and cookies. The document is intended as an introduction to JavaScript for learning its basic concepts.
The document discusses JavaScript functions and events. It explains that functions allow code to be reused by defining blocks of code that can be called from different parts of a program. Functions can take parameters and return values. Events trigger JavaScript code to run in response to user actions or browser events like clicking a button. Common events include onclick, which fires when a user clicks an element, and onsubmit, which fires when a form is submitted. The document provides examples of defining and calling functions, passing parameters to functions, and using return values. It also shows examples of handling the onclick and onsubmit events.
JavaScript variables hold values and are declared with var. Variable names are case sensitive and must begin with a letter or underscore. Variables can hold numbers, strings, Booleans, objects, and null values. Arrays are objects that hold multiple values in a single variable. Functions are blocks of code that perform tasks and are executed by events or calls. Objects store related data and functions to represent self-contained entities.
JavaScript is a scripting language that adds interactivity to HTML pages. It works in all major browsers and can be embedded directly into HTML. JavaScript code is executed by the browser in the sequence it is written. JavaScript statements can be grouped into blocks and functions. JavaScript can react to events like clicks or page loads, manipulate HTML elements, and read/write cookies. To insert JavaScript into an HTML page, use the <script> tag. Functions and events are commonly used together, where functions execute when events occur. JavaScript also includes conditional statements, loops, and popup boxes to display alerts, prompts, and confirmations to users.
The document introduces JavaScript and discusses some key concepts:
1. It defines scripting languages and lists JavaScript, PHP and Python as examples. It also discusses some common applications of scripting languages.
2. It explains how the <script> tag is used to define client-side scripts in HTML and some common attributes of the tag like async, defer and src.
3. It provides an overview of JavaScript, covering data types, variables, operators and more. Arithmetic, comparison, logical and assignment operators are defined along with examples.
var year= prompt("Enter your birth year");
if(year >= 1970 && year <= 1975){
alert("Your age is between 38-43 years old");
} else if(year >= 1976 && year <= 1980){
alert("Your age is between 33-37 years old");
} else if(year >= 1981 && year <= 1985){
alert("Your age is between 28-32 years old");
} else if(year >= 1986 && year <= 2013){
alert("Your age is between 0-27 years old");
}
JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, Opera. and In Java script different different operator, and variables include.
JavaScript is a versatile programming language primarily used for building dynamic and interactive web applications. Developed by Netscape Communications Corporation in the mid-1990s, JavaScript has since become one of the most popular programming languages worldwide. Here's a detailed description of JavaScript:
Introduction to JavaScript:
JavaScript is a high-level, interpreted programming language that allows developers to add functionality, interactivity, and behavior to web pages. Unlike server-side languages like PHP or Python, JavaScript is executed on the client-side, meaning it runs within the user's web browser. This enables dynamic manipulation of webpage content without requiring communication with the server.
The document provides an overview of VBScript, including how it works when inserted into HTML documents, how to format VBScript code within HTML tags, and where to place VBScript code within an HTML document. It also discusses VBScript variables like declaring, assigning values to, and creating array variables. Finally, it covers VBScript procedures like Sub and Function procedures.
JavaScript is a scripting language that can be inserted into HTML pages and used to program the behavior of web pages. It allows web pages to be dynamic and interactive. JavaScript code is placed between <script> and </script> tags and can manipulate HTML elements and write to the document. Variables, functions, conditional statements, and operators allow JavaScript code to run conditionally based on events or user input. JavaScript is case sensitive, uses semicolons, and has both local and global variables. Common data types include numbers, strings, arrays, and objects.
JavaScript is a dynamic programming language used widely in web pages. It allows client-side scripts to interact with users and dynamically update pages. JavaScript code can be placed within <script> tags in HTML pages or external .js files. Common uses of JavaScript include basic arithmetic, variables, functions, objects, arrays, conditional logic, and DOM manipulation. Key JavaScript concepts covered in the document include data types, operators, variables, functions, objects, arrays, conditional statements, and the Date object.
This document discusses JavaScript as a scripting language that allows for dynamic web pages. It covers running JavaScript code using <script> tags, working with variables and data types, operators and expressions, conditional statements like if/else and switch, and loops. Key points include JavaScript being interpreted rather than compiled, adding JavaScript via embedded, inline, or external code, and using variables, comments, arithmetic, comparison, assignment and logical operators.
Conditional statements in JavaScript allow code to execute differently depending on certain conditions. There are several conditional statements in JavaScript:
1. The if statement executes code if a condition is true.
2. The if/else statement executes one block of code if the condition is true and another if it is false.
3. The if/else if statement allows evaluating multiple conditions and executing different code blocks based on which conditions are true.
The document provides an overview of key topics in JavaScript including:
- Introduction to client-side scripting and how JavaScript is used
- JavaScript types like numbers, strings, objects
- Variables, operators, and conditional statements in JavaScript
- Loops, popup boxes, events, arrays, functions and how to use JavaScript in forms and validation
It serves as a syllabus or outline for learning JavaScript fundamentals and applications.
JavaScript is a scripting language used to make web pages interactive. It is loosely based on Java and runs in web browsers to manipulate HTML content and handle user events. JavaScript can be used to validate form data, create dynamic interfaces, and modify page elements. It is an interpreted language that is lightweight, open, and integrated with HTML and Java.
Jquery is a JavaScript library that simplifies HTML document traversal, event handling, animating, and Ajax interactions. It is built on JavaScript and provides shortcuts and abstractions for many common tasks. Some key benefits of Jquery include providing cross-browser compatibility, an easy to use syntax, and a large number of plugins and functions to extend its capabilities.
The document discusses loops and arrays in JavaScript. It describes the different types of loops - while, do-while and for loops. It provides examples to demonstrate each loop. It also describes arrays, including single and multi-dimensional arrays. It explains how to declare and access array elements. Finally, it discusses various array methods like concat, join, push etc and provides examples to use these methods.
Skybuffer SAM4U tool for SAP license adoptionTatiana Kojar
Manage and optimize your license adoption and consumption with SAM4U, an SAP free customer software asset management tool.
SAM4U, an SAP complimentary software asset management tool for customers, delivers a detailed and well-structured overview of license inventory and usage with a user-friendly interface. We offer a hosted, cost-effective, and performance-optimized SAM4U setup in the Skybuffer Cloud environment. You retain ownership of the system and data, while we manage the ABAP 7.58 infrastructure, ensuring fixed Total Cost of Ownership (TCO) and exceptional services through the SAP Fiori interface.
A Comprehensive Guide to DeFi Development Services in 2024Intelisync
DeFi represents a paradigm shift in the financial industry. Instead of relying on traditional, centralized institutions like banks, DeFi leverages blockchain technology to create a decentralized network of financial services. This means that financial transactions can occur directly between parties, without intermediaries, using smart contracts on platforms like Ethereum.
In 2024, we are witnessing an explosion of new DeFi projects and protocols, each pushing the boundaries of what’s possible in finance.
In summary, DeFi in 2024 is not just a trend; it’s a revolution that democratizes finance, enhances security and transparency, and fosters continuous innovation. As we proceed through this presentation, we'll explore the various components and services of DeFi in detail, shedding light on how they are transforming the financial landscape.
At Intelisync, we specialize in providing comprehensive DeFi development services tailored to meet the unique needs of our clients. From smart contract development to dApp creation and security audits, we ensure that your DeFi project is built with innovation, security, and scalability in mind. Trust Intelisync to guide you through the intricate landscape of decentralized finance and unlock the full potential of blockchain technology.
Ready to take your DeFi project to the next level? Partner with Intelisync for expert DeFi development services today!
Ivanti’s Patch Tuesday breakdown goes beyond patching your applications and brings you the intelligence and guidance needed to prioritize where to focus your attention first. Catch early analysis on our Ivanti blog, then join industry expert Chris Goettl for the Patch Tuesday Webinar Event. There we’ll do a deep dive into each of the bulletins and give guidance on the risks associated with the newly-identified vulnerabilities.
This presentation provides valuable insights into effective cost-saving techniques on AWS. Learn how to optimize your AWS resources by rightsizing, increasing elasticity, picking the right storage class, and choosing the best pricing model. Additionally, discover essential governance mechanisms to ensure continuous cost efficiency. Whether you are new to AWS or an experienced user, this presentation provides clear and practical tips to help you reduce your cloud costs and get the most out of your budget.
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUpanagenda
Webinar Recording: https://www.panagenda.com/webinars/hcl-notes-und-domino-lizenzkostenreduzierung-in-der-welt-von-dlau/
DLAU und die Lizenzen nach dem CCB- und CCX-Modell sind für viele in der HCL-Community seit letztem Jahr ein heißes Thema. Als Notes- oder Domino-Kunde haben Sie vielleicht mit unerwartet hohen Benutzerzahlen und Lizenzgebühren zu kämpfen. Sie fragen sich vielleicht, wie diese neue Art der Lizenzierung funktioniert und welchen Nutzen sie Ihnen bringt. Vor allem wollen Sie sicherlich Ihr Budget einhalten und Kosten sparen, wo immer möglich. Das verstehen wir und wir möchten Ihnen dabei helfen!
Wir erklären Ihnen, wie Sie häufige Konfigurationsprobleme lösen können, die dazu führen können, dass mehr Benutzer gezählt werden als nötig, und wie Sie überflüssige oder ungenutzte Konten identifizieren und entfernen können, um Geld zu sparen. Es gibt auch einige Ansätze, die zu unnötigen Ausgaben führen können, z. B. wenn ein Personendokument anstelle eines Mail-Ins für geteilte Mailboxen verwendet wird. Wir zeigen Ihnen solche Fälle und deren Lösungen. Und natürlich erklären wir Ihnen das neue Lizenzmodell.
Nehmen Sie an diesem Webinar teil, bei dem HCL-Ambassador Marc Thomas und Gastredner Franz Walder Ihnen diese neue Welt näherbringen. Es vermittelt Ihnen die Tools und das Know-how, um den Überblick zu bewahren. Sie werden in der Lage sein, Ihre Kosten durch eine optimierte Domino-Konfiguration zu reduzieren und auch in Zukunft gering zu halten.
Diese Themen werden behandelt
- Reduzierung der Lizenzkosten durch Auffinden und Beheben von Fehlkonfigurationen und überflüssigen Konten
- Wie funktionieren CCB- und CCX-Lizenzen wirklich?
- Verstehen des DLAU-Tools und wie man es am besten nutzt
- Tipps für häufige Problembereiche, wie z. B. Team-Postfächer, Funktions-/Testbenutzer usw.
- Praxisbeispiele und Best Practices zum sofortigen Umsetzen
Your One-Stop Shop for Python Success: Top 10 US Python Development Providersakankshawande
Simplify your search for a reliable Python development partner! This list presents the top 10 trusted US providers offering comprehensive Python development services, ensuring your project's success from conception to completion.
Trusted Execution Environment for Decentralized Process MiningLucaBarbaro3
Presentation of the paper "Trusted Execution Environment for Decentralized Process Mining" given during the CAiSE 2024 Conference in Cyprus on June 7, 2024.
Introduction of Cybersecurity with OSS at Code Europe 2024Hiroshi SHIBATA
I develop the Ruby programming language, RubyGems, and Bundler, which are package managers for Ruby. Today, I will introduce how to enhance the security of your application using open-source software (OSS) examples from Ruby and RubyGems.
The first topic is CVE (Common Vulnerabilities and Exposures). I have published CVEs many times. But what exactly is a CVE? I'll provide a basic understanding of CVEs and explain how to detect and handle vulnerabilities in OSS.
Next, let's discuss package managers. Package managers play a critical role in the OSS ecosystem. I'll explain how to manage library dependencies in your application.
I'll share insights into how the Ruby and RubyGems core team works to keep our ecosystem safe. By the end of this talk, you'll have a better understanding of how to safeguard your code.
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfChart Kalyan
A Mix Chart displays historical data of numbers in a graphical or tabular form. The Kalyan Rajdhani Mix Chart specifically shows the results of a sequence of numbers over different periods.
Fueling AI with Great Data with Airbyte WebinarZilliz
This talk will focus on how to collect data from a variety of sources, leveraging this data for RAG and other GenAI use cases, and finally charting your course to productionalization.
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframePrecisely
Inconsistent user experience and siloed data, high costs, and changing customer expectations – Citizens Bank was experiencing these challenges while it was attempting to deliver a superior digital banking experience for its clients. Its core banking applications run on the mainframe and Citizens was using legacy utilities to get the critical mainframe data to feed customer-facing channels, like call centers, web, and mobile. Ultimately, this led to higher operating costs (MIPS), delayed response times, and longer time to market.
Ever-changing customer expectations demand more modern digital experiences, and the bank needed to find a solution that could provide real-time data to its customer channels with low latency and operating costs. Join this session to learn how Citizens is leveraging Precisely to replicate mainframe data to its customer channels and deliver on their “modern digital bank” experiences.
Have you ever been confused by the myriad of choices offered by AWS for hosting a website or an API?
Lambda, Elastic Beanstalk, Lightsail, Amplify, S3 (and more!) can each host websites + APIs. But which one should we choose?
Which one is cheapest? Which one is fastest? Which one will scale to meet our needs?
Join me in this session as we dive into each AWS hosting service to determine which one is best for your scenario and explain why!
Monitoring and Managing Anomaly Detection on OpenShift.pdfTosin Akinosho
Monitoring and Managing Anomaly Detection on OpenShift
Overview
Dive into the world of anomaly detection on edge devices with our comprehensive hands-on tutorial. This SlideShare presentation will guide you through the entire process, from data collection and model training to edge deployment and real-time monitoring. Perfect for those looking to implement robust anomaly detection systems on resource-constrained IoT/edge devices.
Key Topics Covered
1. Introduction to Anomaly Detection
- Understand the fundamentals of anomaly detection and its importance in identifying unusual behavior or failures in systems.
2. Understanding Edge (IoT)
- Learn about edge computing and IoT, and how they enable real-time data processing and decision-making at the source.
3. What is ArgoCD?
- Discover ArgoCD, a declarative, GitOps continuous delivery tool for Kubernetes, and its role in deploying applications on edge devices.
4. Deployment Using ArgoCD for Edge Devices
- Step-by-step guide on deploying anomaly detection models on edge devices using ArgoCD.
5. Introduction to Apache Kafka and S3
- Explore Apache Kafka for real-time data streaming and Amazon S3 for scalable storage solutions.
6. Viewing Kafka Messages in the Data Lake
- Learn how to view and analyze Kafka messages stored in a data lake for better insights.
7. What is Prometheus?
- Get to know Prometheus, an open-source monitoring and alerting toolkit, and its application in monitoring edge devices.
8. Monitoring Application Metrics with Prometheus
- Detailed instructions on setting up Prometheus to monitor the performance and health of your anomaly detection system.
9. What is Camel K?
- Introduction to Camel K, a lightweight integration framework built on Apache Camel, designed for Kubernetes.
10. Configuring Camel K Integrations for Data Pipelines
- Learn how to configure Camel K for seamless data pipeline integrations in your anomaly detection workflow.
11. What is a Jupyter Notebook?
- Overview of Jupyter Notebooks, an open-source web application for creating and sharing documents with live code, equations, visualizations, and narrative text.
12. Jupyter Notebooks with Code Examples
- Hands-on examples and code snippets in Jupyter Notebooks to help you implement and test anomaly detection models.
Astute Business Solutions | Oracle Cloud Partner |
Java scripts
1. How to Handle Simple Browsers ::
-----------------------------------------
Browsers that do not support JavaScript, will display JavaScript as page content.
To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag should
be used to "hide" the JavaScript.
Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of comment)
after the last JavaScript statement, like this:
<html>
<body>
<script type="text/javascript">
<!--
document.write("Hello World!");
//-->
</script>
</body>
</html>
The two forward slashes at the end of comment line (//) is the JavaScript comment symbol. This prevents
JavaScript from executing the --> tag.
JavaScript Where To
================
JavaScripts in the body section will be executed WHILE the page loads.
JavaScripts in the head section will be executed when CALLED.
Where to Put the JavaScript
JavaScripts in a page will be executed immediately while the page loads into the browser. This is not
always what we want. Sometimes we want to execute a script when a page loads, other times when a
user triggers an event.
Scripts in <head>
Scripts to be executed when they are called, or when an event is triggered, go in the head section.
If you place a script in the head section, you will ensure that the script is loaded before anyone uses it.
Example
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event"); //It is used to show the Messagebox with content
}
</script>
</head>
<body onload="message()">
</body>
</html>
Scripts in <body>
2. ===============
Scripts to be executed when the page loads go in the body section.
If you place a script in the body section, it generates the content of a page.
Example
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("This message is written by JavaScript");
</script>
</body>
</html>
Scripts in <head> and <body>
=======================
You can place an unlimited number of scripts in your document, so you can have scripts in both the body
and the head section.
<html>
<head>
<script type="text/javascript">
....
</script>
</head>
<body>
<script type="text/javascript">
....
</script>
</body>
Using an External JavaScript
===================
If you want to run the same JavaScript on several pages, without having to write the same script on every
page, you can write a JavaScript in an external file.
Save the external JavaScript file with a .js file extension.
Note: The external script cannot contain the <script> tag!
To use the external script, point to the .js file in the "src" attribute of the <script> tag:
Example
<html>
<head>
<script type="text/javascript" src="xxx.js"></script>
</head>
<body>
</body>
</html>
Note: Remember to place the script exactly where you normally would write the script!
****
The semicolon is optional (according to the JavaScript standard), and the browser is supposed to
3. interpret the end of the line as the end of the statement. Because of this you will often see examples
without the semicolon at the end.
Note: Using semicolons makes it possible to write multiple statements on one line.
JavaScript Blocks
============
JavaScript statements can be grouped together in blocks.
Blocks start with a left curly bracket {, and ends with a right curly bracket }.
The purpose of a block is to make the sequence of statements execute together.
This example will write a heading and two paragraphs to a web page:
Example
<script type="text/javascript">
{
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
}
</script>
Declaring (Creating) JavaScript Variables
============================
Creating variables in JavaScript is most often referred to as "declaring" variables.
You can declare JavaScript variables with the var statement:
var x;
var carname;
After the declaration shown above, the variables are empty (they have no values yet).
However, you can also assign values to the variables when you declare them:
var x=5;
var carname="Volvo";
After the execution of the statements above, the variable x will hold the value 5, and carname will hold the
value Volvo.
Note: When you assign a text value to a variable, use quotes around the value.
Assigning Values to Undeclared JavaScript Variables
If you assign values to variables that have not yet been declared, the variables will automatically be
declared.
These statements:
x=5;
carname="Volvo";
have the same effect as:
var x=5;
var carname="Volvo";
Redeclaring JavaScript Variables
=======================
4. If you redeclare a JavaScript variable, it will not lose its original value.
var x=5;
var x;
After the execution of the statements above, the variable x will still have the value of 5. The value of x is
not reset (or cleared) when you redeclare it.
JavaScript Arithmetic
As with algebra, you can do arithmetic operations with JavaScript variables:
y=x-5;
z=y+5;
The + Operator Used on Strings
=======================
The + operator can also be used to add string variables or text values together.
To add two or more string variables together, use the + operator.
txt1="What a very";
txt2="nice day";
txt3=txt1+txt2;
After the execution of the statements above, the variable txt3 contains "What a verynice day".
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;
After the execution of the statements above, the variable txt3 contains:
"What a very nice day"
Example :-
<html>
<body>
<script type="text/javascript">
x=5+5;
document.write(x);
document.write("<br />");
x="5"+"5";
document.write(x);
document.write("<br />");
x=5+"5";
document.write(x);
document.write("<br />");
x="5"+5;
document.write(x);
document.write("<br />");
</script>
<p>The rule is: If you add a number and a string, the result will be a string.</p>
5. </body>
</html>
Output :-
10
55
55
55
The rule is: If you add a number and a string, the result will be a string.
JavaScript Comparison and Logical Operators
===============================
Comparison and Logical operators are used to test for true or false.
Comparison Operators
Comparison operators are used in logical statements to determine equality or difference between
variables or values.
Given that x=5, the table below explains the comparison operators:
Operator Description Example
== is equal to x==8 is false
=== is exactly equal to (value and type) x===5 is true
x==="5" is false
!= is not equal x!=8 is true
> is greater than x>8 is false
< is less than x<8 is true
>= is greater than or equal to x>=8 is false
<= is less than or equal to x<=8 is true
How Can it be Used
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");
You will learn more about the use of conditional statements in the next chapter of this tutorial.
Logical Operators
Logical operators are used to determine the logic between variables or values.
Given that x=6 and y=3, the table below explains the logical operators:
Operator Description Example
&& and (x < 10 && y > 1) is true
|| or (x==5 || y==5) is false
! not !(x==y) is true
Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some
condition.
Syntax
variablename=(condition)?value1:value2
6. Example
greeting=(visitor=="PRES")?"Dear President ":"Dear "; //No Space
If the variable visitor has the value of "PRES", then the variable greeting will be assigned the value "Dear
President " else it will be assigned "Dear".
JavaScript If...Else Statements
========================
* 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
* 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
Example :
if and if else ::
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
if else if ::
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
}
Swich Case ::
switch (favoritemovie){
case "Titanic":
alert("Not a bad choice!")
break;
case "Water World":
alert("No comment")
break;
case "Scream 2":
alert("It has its moments")
break;
default : alert("I'm sure it was great");
}
7. JavaScript Popup Boxes
Alert Box
======================
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");
Example
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("I am an alert box!");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show alert box" />
</body>
</html>
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");
Example
<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button");
if (r==true)
{
document.write("You pressed OK!");
}
else
{
document.write("You pressed Cancel!");
}
8. }
</script>
</head>
<body>
<input type="button" onclick="show_confirm()" value="Show confirm box" />
</body>
</html>
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");
Example
<html>
<head>
<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>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Show prompt box" />
</body>
</html>
Function :::
===============
word function is in lower case
with no parameter
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello World!");
}
</script>
</head>
9. <body>
<form>
<input type="button" value="Click me!" onclick="displaymessage()" />
</form>
</body>
</html>
Function with return Type :
<html>
<head>
<script type="text/javascript">
function product(a,b)
{
return a*b;
}
</script>
</head>
<body>
<script type="text/javascript">
document.write(product(4,3));
</script>
</body>
</html>
The for Loop
=========
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
While Loop
========
<html>
<body>
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("The number is " + i);
document.write("<br />");
i++;
}
10. </script>
</body>
</html>
Do-While Lop
============
<html>
<body>
<script type="text/javascript">
var i=0;
do
{
document.write("The number is " + i);
document.write("<br />");
i++;
}
while (i<=5);
</script>
</body>
The break Statement
====================
The break statement will break the loop and continue executing the code that follows after the loop (if
any).
Example
<html>
<body>
<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>
</body>
</html>
The continue Statement
=======================
The continue statement will break the current loop and continue with the next value.
Example
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
11. if (i==3)
{
continue;
}
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
JavaScript For...In Statement(For each Loop)
=====================
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
}
Note: The code in the body of the for...in loop is executed once for each element/property.
Note: The variable argument can be a named variable, an array element, or a property of an object.
Example
Use the for...in statement to loop through an array:
Example
<html>
<body>
<script type="text/javascript">
var x;
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";
for (x in mycars)
{
document.write(mycars[x] + "<br />");
}
</script>
</body>
</html>
Events (http://www.w3schools.com/jsref/jsref_events.asp) All events with discription
=======================
By using JavaScript, we have the ability to create dynamic web pages. 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.
12. 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
Note: Events are normally used in combination with functions, and the function will not be executed
before the event occurs!
For a complete reference of the events recognized by JavaScript, go to our complete Event reference.
onLoad and onUnload
The onLoad and onUnload events are triggered when the user enters or leaves the page.
The onLoad event is often used to check the visitor's browser type and browser version, and load the
proper version of the web page based on the information.
Both the onLoad and onUnload events are also often used to deal with cookies that should be set when a
user enters or leaves a page. For example, you could have a popup asking for the user's name upon his
first arrival to your page. The name is then stored in a cookie. Next time the visitor arrives at your page,
you could have another popup saying something like: "Welcome John Doe!".
onFocus, onBlur and onChange
The onFocus, onBlur and onChange events are often used in combination with validation of form fields.
Below is an example of how to use the onChange event. The checkEmail() function will be called
whenever the user changes the content of the field:
<input type="text" size="30" id="email" onchange="checkEmail()">
onSubmit
The onSubmit event is used to validate ALL form fields before submitting it.
Below is an example of how to use the onSubmit event. The checkForm() function will be called when the
user clicks the submit button in the form. If the field values are not accepted, the submit should be
cancelled. The function checkForm() returns either true or false. If it returns true the form will be
submitted, otherwise the submit will be cancelled:
<form method="post" action="xxx.htm" onsubmit="return checkForm()">
onMouseOver and onMouseOut
onMouseOver and onMouseOut are often used to create "animated" buttons.
Below is an example of an onMouseOver event. An alert box appears when an onMouseOver event is
detected:
<a href="http://www.w3schools.com" onmouseover="alert('An onMouseOver event');return false"><img
src="w3s.gif" alt="W3Schools" /></a>
JavaScript - Catching Errors(Try.............catch Statement)
===============================
When browsing Web pages on the internet, we all have seen a JavaScript alert box telling us there is a
13. runtime error and asking "Do you wish to debug?". Error message like this may be useful for developers
but not for users. When users see errors, they often leave the Web page.
This chapter will teach you how to catch and handle JavaScript error messages, so you don't lose your
audience.
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!
Example 1
The example below is supposed to alert "Welcome guest!" when the button is clicked. However, there's a
typo in the message() function. alert() is misspelled as adddlert(). A JavaScript error occurs. The catch
block catches the error and executes a custom code to handle it. The code displays a custom error
message informing the user what happened:
Example
<html>
<head>
<script type="text/javascript">
var txt=""
function message()
{
try
{
adddlert("Welcome guest!");
}
catch(err)
{
txt="There was an error on this page.nn";
txt+="Error description: " + err.description + "nn";
txt+="Click OK to continue.nn";
alert(txt);
}
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>
The next example uses a confirm box to display a custom message telling users they can click OK to
14. continue viewing the page or click Cancel to go to the homepage. If the confirm method returns false, the
user clicked Cancel, and the code redirects the user. If the confirm method returns true, the code does
nothing:
Example
<html>
<head>
<script type="text/javascript">
var txt=""
function message()
{
try
{
adddlert("Welcome guest!");
}
catch(err)
{
txt="There was an error on this page.nn";
txt+="Click OK to continue viewing this page,n";
txt+="or Cancel to return to the home page.nn";
if(!confirm(txt))
{
document.location.href="http://www.w3schools.com/";
}
}
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>
JavaScript Special Characters
===========================
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.
Look at the following JavaScript code:
var txt="We are the so-called "Vikings" from the north.";
document.write(txt);
In JavaScript, a string is started and stopped with either single or double quotes. This means that the
string above will be chopped to: We are the so-called
To solve this problem, you must place a backslash () before each double quote in "Viking". This
turns each double quote into a string literal:
var txt="We are the so-called "Vikings" from the north.";
document.write(txt);
15. JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.
Here is another example:
document.write ("You & I are singing!");
The example above will produce the following output:
You & I are singing!
The table below lists other special characters that can be added to a text string with the backslash sign:
Code Outputs
' single quote
" double quote
& ampersand
backslash
n new line
r carriage return
t tab
b backspace
f form feed
JavaScript Guidelines
============================
Some other important things to know when scripting with JavaScript.
JavaScript is Case Sensitive
A function named "myfunction" is not the same as "myFunction" and a variable named "myVar" is not the
same as "myvar".
JavaScript is case sensitive - therefore watch your capitalization closely when you create or call variables,
objects and functions.
White Space
JavaScript ignores extra spaces. You can add white space to your script to make it more readable.
The following lines are equivalent:
name="Hege";
name = "Hege";
Break up a Code Line
You can break up a code line within a text string with a backslash. The example below will be displayed
properly:
document.write("Hello
World!");
However, you cannot break up a code line like this:
document.write
("Hello World!");
JavaScript Objects Introduction
=============================
16. JavaScript Objects Introduction
previous next
JavaScript is an Object Oriented Programming (OOP) language.
An OOP language allows you to define your own objects and make your own variable types.
Object Oriented Programming
JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define
your own objects and make your own variable types.
Properties
Properties are the values associated with an object.
In the following example we are using the length property of the String object to return the number of
characters in a string:
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.length);
</script>
The output of the code above will be:
12
JavaScript Objects Introduction
JavaScript is an Object Oriented Programming (OOP) language.
An OOP language allows you to define your own objects and make your own variable types.
Object Oriented Programming
JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define
your own objects and make your own variable types.
However, creating your own objects will be explained later, in the Advanced JavaScript section. We will
start by looking at the built-in JavaScript objects, and how they are used. The next pages will explain each
built-in JavaScript object in detail.
Note that an object is just a special kind of data. An object has properties and methods.
Properties
==================
Properties are the values associated with an object.
In the following example we are using the length property of the String object to return the number of
characters in a string:
<script type="text/javascript">
var txt="Hello World!";
document.write(txt.length);
</script>
The output of the code above will be:
12
17. Methods
================
Methods are the actions that can be performed on objects.
In the following example we are using the toUpperCase() method of the String object to display a text in
uppercase letters:
<script type="text/javascript">
var str="Hello world!";
document.write(str.toUpperCase());
</script>
The output of the code above will be:
HELLO WORLD!
String Functions :
=================
<html>
<body>
<script type="text/javascript">
var txt="Hello World!";
document.write("<p>Big: " + txt.big() + "</p>"); O/p Big: Hello World!
document.write("<p>Small: " + txt.small() + "</p>"); O/p :Small: Hello
World!
document.write("<p>Bold: " + txt.bold() + "</p>"); O/p :Bold: Hello
World!
document.write("<p>Italic: " + txt.italics() + "</p>"); O/p :Italic: Hello
World!
document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>"); O/p :Blink: Hello
World! (does not work in IE) //here Hello World will continue blink !
document.write("<p>Fixed: " + txt.fixed() + "</p>"); O/p: Fixed: Hello World!
document.write("<p>Strike: " + txt.strike() + "</p>"); O/P:Strike: Hello
World!
document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>"); O/P:Fontsize: Hello
World!
document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>"); Lowercase: hello
world!
document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>"); Uppercase: HELLO
WORLD!
document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>");
document.write("<p>Subscript: " + txt.sub() + "</p>"); Subscript: Hello World!
// O/p is not shown in wordpad properly
document.write("<p>Superscript: " + txt.sup() + "</p>"); Superscript: Hello
World! //O/p is not shown in wordpad properly
18. document.write("<p>Link: " + txt.link("http://www.w3schools.com") + "</p>"); Link: Hello World
//Now it becomes link now
</script>
</body>
</html>
<html>
<body>
String always starts from zero(0)
index function
=============
<script type="text/javascript">
var str="Hello world!";
document.write(str.indexOf("Hello") + "<br />"); O/p : 1
document.write(str.indexOf("World") + "<br />"); O/p : -1(because "W" not found its is
"w")
document.write(str.indexOf("world")); O/p : 6
</script>
</body>
</html>
match function
=========
It will return string/string portion whereever it will be found .........return null if not match
<html>
<body>
<script type="text/javascript">
var str="Hello world!";
document.write(str.match("world") + "<br />"); world
document.write(str.match("World") + "<br />"); null
document.write(str.match("worlld") + "<br />"); null
document.write(str.match("world!")); world!
</script>
</body>
</html>
Replace Function
===============
it will replace string
it is necessary to pass the Forward slash in the starting and in the end of string that is need to
replace
<html>
<body>
<script type="text/javascript">
19. var str="Visit Microsoft!";
document.write(str.replace(/Microsoft/,"W3Schools")); Visit W3Schools!
</script>
</body>
</html>
Definition and usage
=========================
The constructor property is a reference to the function that created the object.::::::::::::::::
Syntax
object.constructor
Example
In this example we will show how to use the constructor property:
<script type="text/javascript">
var test=new String();
if (test.constructor==Array)
{
document.write("This is an Array");
}
if (test.constructor==Boolean)
{
document.write("This is a Boolean");
}
if (test.constructor==Date)
{
document.write("This is a Date");
}
if (test.constructor==String)
{
document.write("This is a String");
}
</script>
The output of the code above will be:
This is a String
The prototype property allows you to add properties and methods to an object. ::::::::::::::
Syntax
object.prototype.name=value
Example
In this example we will show how to use the prototype property to add a property to an object:
<script type="text/javascript">
function employee(name,jobtitle,born)
{
this.name=name;
20. this.jobtitle=jobtitle;
this.born=born;
}
var fred=new employee("Fred Flintstone","Caveman",1970): /// employee is not the class while even
we can creates its object and assign the values to its property and create too.
employee.prototype.salary=null; /// created new property
fred.salary=20000;
document.write(fred.salary);
</script>
The output of the code above will be:
20000
The anchor() method is used to create an HTML anchor. ::::::::::::::::::::::::
Syntax
stringObject.anchor(anchorname)
Parameter Description
anchorname Required. Defines a name for the anchor
Example
In this example we will add an anchor to a text:
<script type="text/javascript">
var txt="Hello world!";
document.write(txt.anchor("myanchor"));
</script>
The code above could be written in plain HTML, like this:
<a name="myanchor">Hello world!</a>
The charAt() method returns the character at a specified position::::::::::::::::::::::::::::::::::
Syntax
stringObject.charAt(index)
Parameter Description
index Required. A number representing a position in the string
Tips and Notes
Note: The first character in the string is at position 0.
Example
In the string "Hello world!", we will return the character at position 1:
<script type="text/javascript">
var str="Hello world!";
document.write(str.charAt(1));
21. </script>
The output of the code above will be:
e
The charCodeAt() method returns the Unicode of the character at a specified position::::::::::::::::::::::
Syntax
stringObject.charCodeAt(index)
Parameter Description
index Required. A number representing a position in the string
Tips and Notes
Note: The first character in the string is at position 0.
Example
In the string "Hello world!", we will return the Unicode of the character at position 1:
<script type="text/javascript">
var str="Hello world!";
document.write(str.charCodeAt(1));
</script>
The output of the code above will be:
101
The concat() method is used to join two or more strings.::::::::::::::::::::::::
Syntax
stringObject.concat(stringX,stringX,...,stringX)
Parameter Description
stringX Required. One or more string objects to be joined to a string
Example
In the following example we will create two strings and show them as one using concat():
<script type="text/javascript">
var str1="Hello ";
var str2="world!";
document.write(str1.concat(str2));
</script>
The output of the code above will be:
Hello world!
The fromCharCode() takes the specified Unicode values and returns a string.:::::::::::::::::::
Syntax
String.fromCharCode(numX,numX,...,numX)
Parameter Description
numX Required. One or more Unicode values
22. Tips and Notes
Note: This method is a static method of String - it is not used as a method of a String object that
you have created. The syntax is always String.fromCharCode() and not
myStringObject.fromCharCode().
Example
In this example we will write "HELLO" and "ABC" from Unicode:
<script type="text/javascript">
document.write(String.fromCharCode(72,69,76,76,79));
document.write("<br />");
document.write(String.fromCharCode(65,66,67));
</script>
The output of the code above will be:
HELLO
ABC
The lastIndexOf() method returns the position of the last occurrence of a specified string value,
searching backwards from the specified position in a string.::::::
Syntax
stringObject.lastIndexOf(searchvalue,fromindex)
Parameter Description
search Required. Specifies a string value to search for
fromindex Optional. Specifies where to start the search. Starting backwards in the string
Tips and Notes
Note: The lastIndexOf() method is case sensitive!
Note: This method returns -1 if the string value to search for never occurs.
Example
In this example we will do different searches within a "Hello world!" string:
<script type="text/javascript">
var str="Hello world!";
document.write(str.lastIndexOf("Hello") + "<br />");
document.write(str.lastIndexOf("World") + "<br />");
document.write(str.lastIndexOf("world"));
</script>
The output of the code above will be:
0
-1
6
The search() method is used to search a string for a specified value.::::::::::::::::
23. This method supports regular expressions. You can learn about the RegExp object in our JavaScript
tutorial.
Syntax
stringObject.search(searchstring)
Parameter Description
searchstring Required. The value to search for in a string. To perform a case-insensitive search add
an 'i' flag
Tips and Notes
Note: search() is case sensitive.
Note: The search() method returns the position of the specified value in the string. If no match was found
it returns -1.
Example 1 - Standard Search
In the following example we will search for the word "W3Schools":
<script type="text/javascript">
var str="Visit W3Schools!";
document.write(str.search(/W3Schools/));
</script>
The output of the code above will be:
6
Note: In the following example the word "w3schools" will not be found (because the search()
method is case sensitive):
<script type="text/javascript">
var str="Visit W3Schools!";
document.write(str.search(/w3schools/));
</script>
The output of the code above will be:
-1
The slice() method extracts a part of a string and returns the extracted part in a new
string.::::::::::::::::::
Syntax
stringObject.slice(start,end) /// It is based on position not on length unlike substring(based on
length see below)
Parameter Description
start Required. Specify where to start the selection. Must be a number. Starts at 0
end Optional. Specify where to end the selection. Must be a number
Tips and Notes
Tip: You can use negative index numbers to select from the end of the string.
24. Note: If end is not specified, slice() selects all characters from the specified start position and to the end of
the string.
Example 1
In this example we will extract all characters from a string, starting at position 0:
<script type="text/javascript">
var str="Hello happy world!";
document.write(str.slice(0));
</script>
The output of the code above will be:
Hello happy world!
Example 2
In this example we will extract all characters from a string, starting at position 6:
<script type="text/javascript">
var str="Hello happy world!";
document.write(str.slice(6));
</script>
The output of the code above will be:
happy world!
Example 3
In this example we will extract only the first character from a string:
<script type="text/javascript">
var str="Hello happy world!";
document.write(str.slice(0,1));
</script>
The output of the code above will be:
H
The split() method is used to split a string into an array of strings.::::::::::::;;
Syntax
stringObject.split(separator, howmany)
Parameter Description
separator Required. Specifies the character, regular expression, or substring that is used to
determine where to split the string
howmany Optional. Specify how many times split should occur. Must be a numeric value
Tips and Notes
Note: If an empty string ("") is used as the separator, the string is split between each character.
Example
25. In this example we will split up a string in different ways:
<script type="text/javascript">
var str="How are you doing today?";
document.write(str.split(" ") + "<br />");
document.write(str.split("") + "<br />");
document.write(str.split(" ",3));
</script>
The output of the code above will be:
How,are,you,doing,today?
H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
How,are,you
The substr() method extracts a specified number of characters in a string, from a start
index.:::::::::::
Syntax
stringObject.substr(start,length)
Parameter Description
start Required. Where to start the extraction. Must be a numeric value
length Optional. How many characters to extract. Must be a numeric value.
Tips and Notes
Note: To extract characters from the end of the string, use a negative start number (This does not work in
IE).
Note: The start index starts at 0.
Note: If the length parameter is omitted, this method extracts to the end of the string.
Example 1
In this example we will use substr() to extract some characters from a string:
<script type="text/javascript">
var str="Hello world!";
document.write(str.substr(3));
</script>
The output of the code above will be:
lo world!
Example 2
In this example we will use substr() to extract some characters from a string:
<script type="text/javascript">
var str="Hello world!";
document.write(str.substr(3,7)); // Start from 3 and count 7 characters from there
</script>
26. The output of the code above will be:
lo worl
Java Script Regular Expression :
==========================
JavaScript global Property ::::
JavaScript global Property
RegExp Object Reference Complete RegExp Object Reference
Definition and Usage
The global property is used to return whether or not the "g" modifier is used in the regular expression.
The "g" modifier is set if the regular expression should be tested against all possible matches in the string.
This property is "TRUE" if the "g" modifier is set, "FALSE" otherwise.
Syntax
RegExpObject.global
<html>
<body>
<script type="text/javascript">
var str = "Visit W3Schools";
var patt1 = new RegExp("s","g");
if(patt1.global)
{
document.write("Global property is set");
}
else
{
document.write("Global property is NOT set.");
}
</script>
</body>
</html>
o/p Global property is set
JavaScript ignoreCase Property
JavaScript ignoreCase Property
RegExp Object Reference Complete RegExp Object Reference
Definition and Usage
The ignoreCase property is used to return whether or not the "i" modifier is used in the regular
expression.
The "i" modifier is set if the regular expression should ignore the case of characters.
This property is "TRUE" if the "i" modifier is set, "FALSE" otherwise.
Syntax
RegExpObject.ignoreCase
27. <html>
<body>
<script type="text/javascript">
var str = "Visit W3Schools";
var patt1 = new RegExp("S","i");
if(patt1.ignoreCase)
{
document.write("ignoreCase property is set");
}
else
{
document.write("ignoreCase property is NOT set.");
}
</script>
</body>
</html>
o/p=ignoreCase property is set
JavaScript input Property
The input property is the string the pattern match is performed.
<html>
<body>
<script type="text/javascript">
function getRegInput()
{
var patt1 = new RegExp("W3");
var str = document.frm1.txtinput.value;
patt1.test(str); ///????
if(RegExp.input)
{
alert("The input is: " + RegExp.input);
}
else
{
alert("The input does not contain W3");
}
}
</script>
<form name="frm1">
Enter some text and click outside:
<input type="text" name="txtinput" onChange='getRegInput()' /><br />
Input will only show if text contains W3.
</form>
</body>
</html>
28. JavaScript lastIndex Property
The lastIndex property specifies the index (placement) in the string where to start the next match.
The index is a number specifying the placement of the first character after the last match.
This property only works if the "g" modifier is set.
Syntax
RegExpObject.lastIndex
<html>
<body>
<script type="text/javascript">
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
for(i = 0; i < 4; i++)
{
patt1.test(str);
document.write("ain found. index now at: " + patt1.lastIndex);
document.write("<br />");
}
</script>
</body>
</html>
Output :
ain found. index now at: 8
ain found. index now at: 17
ain found. index now at: 28
ain found. index now at: 43
JavaScript lastMatch Property
The lastMatch property is the last matched characters.
Syntax
RegExp.lastMatch
<html>
<body>
<script type="text/javascript">
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
for(i = 0; i < 4; i++)
{
patt1.test(str);
document.write(RegExp.lastMatch);
// document.write(" found. index now at: " + patt1.lastIndex);
document.write("<br />");
}
</script>
</body>
</html>
29. o/p
ain
ain
ain
ain
JavaScript leftContext Property(Nice)
The leftContext property is the substring in front of the characters most recently matched.
This property contains everything from the string from before the match.
Syntax
RegExp.leftContext
<html>
<body>
<script type="text/javascript">
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
for(i = 0; i < 4; i++)
{
patt1.test(str)
document.write(RegExp.lastMatch);
document.write(" found. Text before match: " + RegExp.leftContext);
document.write("<br />");
}
</script>
</body>
</html>
o/p :
ain found. Text before match: The r
ain found. Text before match: The rain in Sp
ain found. Text before match: The rain in Spain stays m
ain found. Text before match: The rain in Spain stays mainly in the pl
JavaScript multiline Property
The multiline property is used to return whether or not the "m" modifier is used in the regular expression.
The "m" modifier is set if the regular expression should be tested against possible matches over multiple
lines.
This property is "TRUE" if the "m" modifier is set, "FALSE" otherwise.
Syntax
RegExpObject.multiline
<html>
<body>
30. <script type="text/javascript">
var str = "Visit W3Schools";
var patt1 = new RegExp("s","m");
if(patt1.multiline)
{
document.write("Multiline property is set"); o/p multiline property is set
}
else
{
document.write("Multiline property is NOT set.");
}
</script>
</body>
</html>
JavaScript rightContext Property
The rightContext property is the substring from after the characters most recently matched.
This property contains everything from the string from after the match.
Syntax
RegExp.rightContext
<html>
<body>
<script type="text/javascript">
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
for(i = 0; i < 4; i++)
{
patt1.test(str);
document.write(RegExp.lastMatch);
document.write(" found. Text after match: " + RegExp.rightContext);
document.write("<br />");
}
</script>
</body>
</html>
ain found. Text after match: in Spain stays mainly in the plain
ain found. Text after match: stays mainly in the plain
ain found. Text after match: ly in the plain
ain found. Text after match:
JavaScript source Property
The source property is used to return the text used for pattern matching.
The returned text is everything except the forward slashes and any flags.
Syntax
RegExpObject.source
<html>
31. <body>
<script type="text/javascript">
var str = "Visit W3Schools";
var patt1 = new RegExp("W3S","g");
document.write("The regular expression is: " + patt1.source);
</script>
</body>
</html>
o/p::The regular expression is: W3S
JavaScript compile() Method
The compile() method is used to change the regular expression.
Syntax
RegExpObject.compile(regexp)
Parameter Description
regexp Required. The new regular expression to search for
Example
In the following example we change the pattern from "Microsoft" to "W3Schools", and then test if we find
the specified pattern in a string:
<script type="text/javascript">
var str="Visit W3Schools";
var patt=new RegExp("Microsoft");
document.write("Test if we find " + patt + " in " + str + ": ")
if (patt.test(str)==true)
{
document.write("Match found!")
}
else
{
document.write("Match not found")
}
patt.compile("W3Schools");
document.write("<br />")
document.write("Test if we find " + patt + " in " + str + ": ")
if (patt.test(str)==true)
{
document.write("Match found!")
}
else
{
document.write("Match not found")
}
32. </script>
The output of the code above will be:
Test if we find /Microsoft/ in Visit W3Schools: Match not found
Test if we find /W3Schools/ in Visit W3Schools: Match found!
JavaScript exec() Method
The exec() method searches a string for a specified value.
This method returns the matched text if a match is found, and null if not.
Syntax
RegExpObject.exec(string)
Parameter Description
RegExpObject Required. The regular expression to use
string Required. The string to search
Example
In the following example we will search for "W3Schools" in a string:
<script type="text/javascript">
var str="Visit W3Schools";
var patt=new RegExp("W3Schools");
document.write(patt.exec(str));
</script>
The output of the code above will be:
W3Schools
JavaScript test() Method
The test() method searches a string for a specified value.
This method returns true if a match is found, and false if not.
Syntax
RegExpObject.test(string)
Parameter Description
RegExpObject Required. The regular expression to use
string Required. The string to search
Example
In the following example we change the pattern from "Microsoft" to "W3Schools", and then test if we find
the specified pattern in a string:
<script type="text/javascript">
var str="Visit W3Schools";
var patt=new RegExp("Microsoft");
33. document.write("Test if we find " + patt + " in " + str + ": ")
if (patt.test(str)==true)
{
document.write("Match found!")
}
else
{
document.write("Match not found")
}
patt.compile("W3Schools");
document.write("<br />")
document.write("Test if we find " + patt + " in " + str + ": ")
if (patt.test(str)==true)
{
document.write("Match found!")
}
else
{
document.write("Match not found")
}
</script>
The output of the code above will be:
Test if we find /Microsoft/ in Visit W3Schools: Match not found
Test if we find /W3Schools/ in Visit W3Schools: Match found!
JavaScript isFinite() Function
The isFinite() function is used to check if a value is a finite number.
Syntax
isFinite(number)
Parameter Description
number Required. The value to be tested
Example
In this example we use isFinite() to check for finite numbers:
<script type="text/javascript">
document.write(isFinite(123)+ "<br />");
document.write(isFinite(-1.23)+ "<br />");
document.write(isFinite(5-2)+ "<br />");
document.write(isFinite(0)+ "<br />");
document.write(isFinite("Hello")+ "<br />");
document.write(isFinite("2005/12/12")+ "<br />");
</script>
34. The output of the code above will be:
true
true
true
true
false
false
JavaScript Number() Function
The Number() function converts the value of an object to a number.
Syntax
Number(object)
Parameter Description
object Required. A JavaScript object
Tips and Notes
Note: If the parameter is a Date object, the Number() function returns the number of milliseconds
since midnight January 1, 1970 UTC.
Note: If the object's value cannot be converted to a number, the Number() function returns NaN.
Example
In this example we will try to convert different objects to numbers:
<script type="text/javascript">
var test1= new Boolean(true);
var test2= new Boolean(false);
var test3= new Date();
var test4= new String("999");
var test5= new String("999 888");
document.write(Number(test1)+ "<br />");
document.write(Number(test2)+ "<br />");
document.write(Number(test3)+ "<br />");
document.write(Number(test4)+ "<br />");
document.write(Number(test5)+ "<br />");
</script>
The output of the code above will be:
1
0
1247394276301
999
NaN
JavaScript isNaN() Function
The isNaN() function is used to check if a value is not a number.
Syntax
35. isNaN(number)
Parameter Description
number Required. The value to be tested
Example
In this example we use isNaN() to check some values:
<script type="text/javascript">
document.write(isNaN(123)+ "<br />");
document.write(isNaN(-1.23)+ "<br />");
document.write(isNaN(5-2)+ "<br />");
document.write(isNaN(0)+ "<br />");
document.write(isNaN("Hello")+ "<br />");
document.write(isNaN("2005/12/12")+ "<br />");
</script>
The output of the code above will be:
false
false
false
false
true
true
JavaScript escape() Function
The escape() function encodes a string, so it can be read on all computers.
Syntax
escape(string)
Parameter Description
string Required. The string to be encoded
Tips and Notes
Note: The escape() function encodes special characters, with the exception of:
*@-_+./
Tip: Use the unescape() function to decode strings encoded with escape().
Note: The escape() and unescape() functions should not be used to encode or decode URIs. Use
encodeURI() and decodeURI() functions instead!
Example
In this example we use escape() to encode strings:
<script type="text/javascript">
document.write(escape("Visit W3Schools!") + "<br />");
document.write(escape("?!=()#%&"));
</script>
36. The output of the code above will be:
Visit%20W3Schools%21
%3F%21%3D%28%29%23%25%26
JavaScript unescape() Function
The unescape() function decodes a string encoded with escape().
Syntax
unescape(string)
Parameter Description
string Required. The string to be decoded
Tips and Notes
Note: The escape() and unescape() functions should not be used to encode or decode URIs. Use
encodeURI() and decodeURI() functions instead!
Example
In this example we first encode the strings with the escape() function, and then decode them with the
unescape() function:
<script type="text/javascript">
var test1="Visit W3Schools!";
test1=escape(test1);
document.write (test1 + "<br />");
test1=unescape(test1);
document.write(test1 + "<br />");
</script>
The output of the code above will be:
Visit%20W3Schools%21
Visit W3Schools!
JavaScript eval() Function // Its important to make the code more smaller.......nice one
The eval() function evaluates a string and executes it as if it was script code.
Syntax
eval(string)
Parameter Description
string Required. The string to be evaluated
Example
In this example we use eval() on some strings and see what it returns:
<script type="text/javascript">
37. eval("x=10;y=20;document.write(x*y)");
document.write("<br />");
document.write(eval("2+2"));
document.write("<br />");
var x=10;
document.write(eval(x+17));
document.write("<br />");
</script>
The output of the code above will be:
200
4
27
JavaScript String() Function
The String() function converts the value of an object to a string.
Syntax
String(object)
Parameter Description
object Required. A JavaScript object
Tips and Notes
Note: The String() function returns the same value as toString() of the individual objects.
Example
In this example we will try to convert different objects to strings:
<script type="text/javascript">
var test1= new Boolean(1);
var test2= new Boolean(0);
var test3= new Boolean(true);
var test4= new Boolean(false);
var test5= new Date();
var test6= new String("999 888");
var test7=12345;
document.write(String(test1)+ "<br />");
document.write(String(test2)+ "<br />");
document.write(String(test3)+ "<br />");
document.write(String(test4)+ "<br />");
document.write(String(test5)+ "<br />");
document.write(String(test6)+ "<br />");
document.write(String(test7)+ "<br />");
</script>
The output of the code above will be:
true
false
38. true
false
Sun Jul 12 2009 15:55:47 GMT+0530 (India Standard Time)
999 888
12345
Examples for Events ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
JavaScript onclick Event
<html>
<body>
Field1: <input type="text" id="field1" value="Hello World!">
<br />
Field2: <input type="text" id="field2">
<br /><br />
Click the button below to copy the content of Field1 to Field2.
<br />
<button onclick="document.getElementById('field2').value=
document.getElementById('field1').value">Copy Text</button>
</body>
</html>
onfocus event
<html>
<head>
<script type="text/javascript">
function setStyle(x)
{
document.getElementById(x).style.background="yellow";
}
</script>
</head>
<body>
First name: <input type="text"
onfocus="setStyle(this.id)" id="fname">
<br />
Last name: <input type="text"
onfocus="setStyle(this.id)" id="lname">
</body>
</html>
onkeydown Event
Browser differences: Internet Explorer uses event.keyCode to retrieve the character that was
pressed and Netscape/Firefox/Opera uses event.which.
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
39. var keynum;
var keychar;
var numcheck;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
numcheck = /d/;
return !numcheck.test(keychar);
}
</script>
<form>
Type some text (numbers not allowed):
<input type="text" onkeydown="return noNumbers(event)" />
</form>
</body>
</html>
Date and Time Section ::::
<html>
<body>
<script type="text/javascript">
document.write(Date());
</script>
</body>
</html>
o/p Sun Jul 12 2009 16:16:31 GMT+0530 (India Standard Time)
<html>
<body>
<script type="text/javascript">
var minutes = 1000*60;
var hours = minutes*60;
var days = hours*24;
var years = days*365;
var d = new Date();
var t = d.getTime();
var y = t/years;
document.write("It's been: " + y + " years since 1970/01/01!");
</script>
40. </body>
</html>
O.p It's been: 39.554654748414514 years since 1970/01/01!
<html>
<body>
<script type="text/javascript">
var d = new Date();
d.setFullYear(1992,10,3);
document.write(d);
</script>
</body>
</html>
O/p :Tue Nov 03 1992 16:16:32 GMT+0530 (India Standard Time)
<html>
<body>
<script type="text/javascript">
var d = new Date();
document.write (d.toUTCString());
</script>
</body>
</html>
Sun, 12 Jul 2009 10:46:34 GMT
<html>
<body>
<script type="text/javascript">
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
document.write("Today it is " + weekday[d.getDay()]); // getDay function will return the number
41. </script>
</body>
</html>
Today is Sunday
Clock
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html>
return current time 16:39:02
Mathematical Function :
Mathematical Methods
In addition to the mathematical constants that can be accessed from the Math object there are also
several methods available.
The following example uses the round() method of the Math object to round a number to the nearest
integer:
document.write(Math.round(4.7));
The code above will result in the following output:
5
42. Random method
The following example uses the random() method of the Math object to return a random number between
0 and 1:
document.write(Math.random());
The code above can result in the following output:
0.6388059778069849
The following example uses the floor() and random() methods of the Math object to return a random
number between 0 and 10:
document.write(Math.floor(Math.random()*11));
The code above can result in the following output:
4
<html>
<body>
<script type="text/javascript">
document.write(Math.random());
</script>
</body>
</html>
<html>
<body>
<script type="text/javascript">
document.write(Math.round(0.60) + "<br />");
document.write(Math.round(0.50) + "<br />");
document.write(Math.round(0.49) + "<br />");
document.write(Math.round(-4.40) + "<br />");
document.write(Math.round(-4.60));
</script>
</body>
</html>
The innerHTML property sets or returns the text of a link.
It will redirect u to the microsoft site
<html>
<head>
<script type="text/javascript">
function changeLink()
{
document.getElementById('myAnchor').innerHTML="Visit W3Schools";
43. document.getElementById('myAnchor').href="http://www.w3schools.com";
document.getElementById('myAnchor').target="_blank";
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.microsoft.com">Visit Microsoft</a>
<input type="button" onclick="changeLink()" value="Change link">
<p>In this example we change the text and the URL of a hyperlink. We also change the target attribute.
The target attribute is by default set to "_self", which means that the link will open in the same window.
By setting the target attribute to "_blank", the link will open in a new window.</p>
</body>
</html>
Regular Expression(RegExp)
What is RegExp
RegExp, is short for regular expression.
When you search in a text, you can use a pattern to describe what you are searching for. RegExp IS this
pattern.
A simple pattern can be a single character.
A more complicated pattern consists of more characters, and can be used for parsing, format checking,
substitution and more.
You can specify where in the string to search, what type of characters to search for, and more.
Defining RegExp
The RegExp object is used to store the search pattern.
We define a RegExp object with the new keyword. The following code line defines a RegExp object called
patt1 with the pattern "e":
var patt1=new RegExp("e");
When you use this RegExp object to search in a string, you will find the letter "e".
Methods of the RegExp Object
The RegExp Object has 3 methods: test(), exec(), and compile().
test()
The test() method searches a string for a specified value. Returns true or false
Example
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free"));
Since there is an "e" in the string, the output of the code above will be:
true
Navigator Object
44. Properties Description
----------------------------------------------------------------------------------------------------
appCodeName The code name of the browser.
appName The name of the browser (ie: Microsoft Internet Explorer).
appVersion Version information for the browser (ie: 4.75 [en] (Win98; U)).
appMinorVersion The minor version number of the browser.
cookieEnabled Boolean that indicates whether the browser has cookies enabled. cpuClass
The type of CPU which may be "x86"
language Returns the default language of the browser version (ie: en-US). NS
and Firefox only.
mimeTypes[] An array of all MIME types supported by the client. NS and Firefox
only.
platform[] The platform of the client's computer (ie: Win32).
plugins An array of all plug-ins currently installed on the client. NS and
Firefox only.
systemLanguage Returns the default language of the operating system (ie: en-us). IE
only.
userAgent String passed by browser as user-agent header. (ie: Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1))
userLanguage Returns the preferred language setting of the user (ie: en-ca). IE only.
mimeTypes An array of MIME type descriptive strings that are supported by the
browser.
onLine A boolean value of true or false.
Image Map Example
<html>
<head>
<script type="text/javascript">
function writeText(txt)
{
document.getElementById("desc").innerHTML=txt;
}
</script>
</head>
<body>
<img src ="planets.gif" width ="145" height ="126" alt="Planets" usemap="#planetmap" />
<map name="planetmap">
<area shape ="rect" coords ="0,0,82,126"
onMouseOver="writeText('The Sun and the gas giant planets like Jupiter are by far the largest
objects in our Solar System.')"
href ="sun.htm" target ="_blank" alt="Sun" />
<area shape ="circle" coords ="90,58,3"
onMouseOver="writeText('The planet Mercury is very difficult to study from the Earth because
it is always so close to the Sun.')"
href ="mercur.htm" target ="_blank" alt="Mercury" />
45. <area shape ="circle" coords ="124,58,8"
onMouseOver="writeText('Until the 1960s, Venus was often considered a twin sister to the
Earth because Venus is the nearest planet to us, and because the two planets seem to share
many characteristics.')"
href ="venus.htm" target ="_blank" alt="Venus" />
</map>
<h4 id="desc"></h4>
</body>
</html>
Timing Object
<html>
<head>
<script type="text/javascript">
function timedMsg()
{
var t=setTimeout("alert('5 seconds!')",5000);
}
</script>
</head>
<body>
<form>
<input type="button" value="Display timed alertbox!" onClick = "timedMsg()">
</form>
<p>Click on the button above. An alert box will be displayed after 5 seconds.</p>
</body>
</html>