Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Tuesday, May 15, 2012

History of Javascript.



JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, which was later renamed to LiveScript, and finally to JavaScript mainly because it was more influenced by the Java programming language.[9][10] LiveScript was the official name for the language when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed JavaScript in a joint announcement with Sun Microsystems on December 4, 1995,[11] when it was deployed in the Netscape browser version 2.0B3.[12]
The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. The final choice of name caused confusion, giving the impression that the language was a spin-off of the Java programming language, and the choice has been characterized by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web programming language.[13][14] It has also been claimed that the language's name is the result of a co-marketing deal between Netscape and Sun, in exchange for Netscape bundling Sun's Java runtime with its then-dominant browser.

JavaScript very quickly gained widespread success as a client-side scripting language for web pages. As a consequence, Microsoft named its implementationJScript to avoid trademark issues. JScript added new date methods to fix the Y2K-problematic methods in JavaScript, which were based on Java'sjava.util.Date class.[15] JScript was included in Internet Explorer 3.0, released in August 1996.
In November 1996, Netscape announced that it had submitted JavaScript to Ecma International for consideration as an industry standard, and subsequent work resulted in the standardized version named ECMAScript.[16]
JavaScript has become one of the most popular programming languages on the web. Initially, however, many professional programmers denigrated the language because its target audience was web authors and other such "amateurs", among other reasons.[17] The advent of Ajax returned JavaScript to the spotlight and brought more professional programming attention. The result was a proliferation of comprehensive frameworks and libraries, improved JavaScript programming practices, and increased usage of JavaScript outside of web browsers, as seen by the proliferation of server-side JavaScript platforms.
In January 2009, the CommonJS project was founded with the goal of specifying a common standard library mainly for JavaScript development outside the browser.[18]

What is Javascript?



JavaScript
 is a prototype-based scripting language that is dynamicweakly typed and has first-class functions. It is a multi-paradigm language, supportingobject-oriented,[5] imperative, and functional[1][6] programming styles.
JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript, implemented as part of a Web browser in order to provide enhanced user interfaces and dynamic websites. This enables programmatic access to computational objects within a host environment.

Source : http://en.wikipedia.org/wiki/JavaScript

Wednesday, July 1, 2009

Javascript E-Mail Validation

Try testing the following form with valid and invalid email addresses. The code uses javascript to match the users input with a regular expression.

The Code
function validate(form_id,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {
alert('Invalid Email Address');
return false;
}
}


Design
In the forms 'onsubmit' code call javascript:return validate('form_id','email_field_id')

<form id="form_id" method="post" action="action.php" onsubmit="javascript:return validate('form_id','email');">
<input type="text" id="email" name="email" />
<input type="submit" value="Submit" />
</form>

Source : http://www.white-hat-web-design.co.uk/articles/js-validation.php

JavaScript Array length Property

The number of elements in a JavaScript array can be retrieved by using the length property of the Array object. Note that this includes any undefined elements.

//Returns 4
var aryTest = [1,2,3,4];
document.write(aryTest.length);


If an element is then added at the 5th position of the array (JavaScript arrays are seeded at 0) the length of the array is 6, even though the 4th position is undefined.

//Returns 6
var aryTest = [1,2,3,4];
aryTest[5] = 5;
document.write(aryTest.length);


So the individual array elements are now:

aryTest[0] = 1
aryTest[1] = 2
aryTest[2] = 3
aryTest[3] = 4
aryTest[4] = undefined
aryTest[5] = 5


From this we can see that the JavaScript array has a length of 6.

The length property of the JavaScript array object can also be used to expand and contract the array.

//Returns 10
var aryTest = [1,2,3,4];
aryTest.length = 10;
document.write(aryTest.length);


The preceding array was initialized to have four elements, then the length property was explicitly set to have 10 elements, which adds six undefined elements to the array.

The length of the array can be similarly contracted.

//Returns 3
var aryTest = [1,2,3,4];
aryTest.length = 3;
document.write(aryTest.length);


In the preceding example, the array is initialized with four elements. When the length is explicitly set to three the fourth element is truncated from the array.

Source : http://blog.techsaints.com/2007/04/28/javascript-array-length-property/

JavaScript Number Validation (Integer)

To validate an integer in JavaScript, use a regular expression:

var NumberToTest = 15;
var IsFound = /^-?\d+$/.test(NumberToTest);
document.write(IsFound);

The ^ symbol specifies that the tested value must begin with a digit (i.e., there can be no non-numeric data before the numeric data begins).
The $ symbol is similarly used to ensure that no non-numeric data comes after the numeric data.
The + symbol matches one or more occurrences of the previous item. In this case, it means that there can be one or more digits in the test string. Without this, 15 would not validate because the test would be looking for a string that started and ended with one digit.

Source : http://blog.techsaints.com/2007/04/10/javascript-number-validation-integer/