-
some stupid things
- if else java style
- for(var x=0;x<2;x++)
-
Array
- var somearray = new Array();
- var 2Darray = new Array(new Array(2),new Array(3));
-
function
-
function changeImage(xyz)
- Remember no var is required for xyz.... inside the method signature
- But xyz act as local variable
- return x;
-
var funcName = changeImage;
- No function bracket
- funcName("some stupid thing");
-
Callback
-
browser supported callback method
- e.g.,
- onload
- onclick
- window.onload = changeImage;
- Just Referencing the method.. not calling it
- How it work ??
- Onload happen ===> window.onload() ===> call changeImage()
- Adv...
- No need to put those event handling thing in the html like onclick etc
- Disadv...
- How to pass variable inside method...
- function literal
- document.getElementById("abc").onclick = function(evt){ changeImage(123);}
- also called as anonymous functions
- window.onload = function(){ ... }
- In this method other function literal can be called
- So When ever HTML page get unloaded, you have to initialize all the function literal methods.
-
Browser
-
cookie
- document.cookie
- navigator.cookieEnabled
-
Form and Validation
-
Accessing element
- getElementById()
-
form object
-
Step 1: onclick="showIt(this.form)"
- Instead of sending this.form... only this can be passed...
- Step 2: function showIt(theForm){ theForm["zipcode"].value };
- form.submit();
-
When to validate??
- Select the input field... onfocus
-
Leave the input field and move to the next one... onblur/onchange
- onchange only diffrence is ... contents needs to be changed
- onchange should not be used...bcoz it won't get trigger for empty element.
-
Regular Expression
-
Pattern
-
pattern = ###
- all numeric
-
pattern = /^\d{5}$/
- All regular expr.. enclosed by /
- d ==> a single numeric digit
- {5} ==> The single digit must repeat 5 times
- $ ==> The string must end with this pattern