Thursday, November 3, 2011

Important javascript Event List & Description

Event?
Event means action. When user click a button means user wants to perform an action. Events like performing:

  1. Click on a button
  2. Press a key
  3. Highlight text
  4. Drag & Drop

List of available javascript Events are given below:*To see the example scroll down
EventDescriptionApplicable for ?
onAbortWhen user cancel image loadingImage
onBlurWhen control lost its FocusButton, Checkbox, FileUpload, Layer, Password, Radio, Reset, Select, Submit, Text, TextArea, Window
onChangeCombo index change/Textbox data changeText, TextArea, Select
onClickMost useful event. Occur when user click on a buttonButton, Checkbox, Link, Radio, Submit
onDblClickWhen user double click on a LinkLink
onFocusWhen an object get focusButton, Checkbox, Radio, Reset, Select, Submit, Text, TextArea
onKeyDownWhen the key is down means pressing timeLink, TextArea
onKeyPressWhen user presses/holds a keyLink, TextArea
onKeyUpWhen user release a keyLink, TextArea
onLoadAfter completion of loading a pageWindow, Image
onMouseDownWhen mouse pressesLink, Button, Document
onMouseMoveWhen user moves the mouseLink, Button, Document
onMouseOutWhen user moves the mouse away from a objectImage, Link
onMouseOverWhen user moves the mouse over a objectImage, Link
onMouseUpWhen user release mouseDocument, Button, Link
onMoveWhen user moves the browser window or a frameDocument, Button, Link
onResetBy clicking on reset ButtonForm
onResizeWhen user resizes the browser window or a frameWindow
onSelectWhen user select textText, TextArea
onSubmitWhen user clicks the submit buttonForm
onUnloadWhen user leaves the page/close the browserWindow

Example onClick Event:
Here i am showing how one can use this event & add event handler. Example covers both asp.net server side control & HTML control. To run this example just copy the below code then run your page. Add the below function in your javascript block:
function funcOnClick()
{
// Code goes here
alert("Click event fired");
// Return false never make a post back to server.
// so one can add validation by using this concept. If return true then the page will be post back to server
return false;
}

Add the handler:
<asp:button runat="server" id="cmdOnClick" text="OnClientClick" onclientclick="return funcOnClick();">
<asp:button runat="server" id="cmdOnClick" text="OnClientClick" onclientclick="return funcOnClick();">
<asp:button runat="server" id="cmdRunTime" text="Server Control onClick">
<input type="button" name="cmdHTML" value="HTML onClick" onclick="return funcOnClick();">

No comments:

Post a Comment