Javascript commands for the most common actions

Some of the most common javascript commands that i quickly managed to collect. This list is going to grow quickly. Stay tuned!!!


Go to the previous page
(back button)
<INPUT TYPE=”button” VALUE=”Back” onClick=”history.go(-1);return true;”>


Most Common EventHandlers

Event Handler Action
onAbort The user stopped loading a page
onBlur The user moves from an object
onChange The user changed an object
onClick The user mouse-clicked an object
onError An error occurred in the script
onFocus The user activates an object
onLoad The object has been loaded
onMouseover The cursor has moved over the object
onMouseout The cursor has moved off the object
onSelect The user selected the object
onSubmit The user submitted a form
onUnload The user leaves the window

..

Writing to HTML body
document.write(“hello Wolrd”);

Alerts
alert(“I m an alert”);

Date functions

function TodaysDate (){
  var Today=new Date();
  var ThisDay=Today.getDate();
  var ThisMonth=Today.getMonth()+1;
  var ThisYear=Today.getFullYear();
return ThisMonth+"/"+ThisDay+"/"+ThisYear;
}

Page Confirmation
<script type=”text/javascript” language=”JavaScript”>
<!–
function go_there()
{
var where_to= confirm(“Do you really want to go to this page??”);
if (where_to== true)
window.location=”http://confirmedpage.com/”;
else
window.location=”http://www.changedmind.com/”;
}
//–>
</script>
<a href=”javascript:go_there()”>New Page</a>

Pop up windows

Option Values Description Version
location yes|no Does the location bar show? ver 1.0
menubar yes|no Does the menubar show? ver 1.0
scrollbars yes|no Do scrollbars show? ver 1.0
status yes|no Does the status bar show| ver 1.0
titlebar yes|no Does the titlebar show? ver 1.0
toolbar yes|no Does the toolbar show? ver 1.0
resizable yes|no Can you resize the window? ver 1.0
height pixels height of window ver 1.0
width pixels width of window ver 1.0
directories yes|no Does the personal toolbar show? ver 1.2
innerHeight pixels specifies the inner height of window ver 1.2
innerWidth pixels specifies the inner width of window ver 1.2
screenX pixels specifies distance from left edge of screen ver 1.2
screenY pixels specifies distance from top edge of screen ver 1.2

and a example for implementation is:
window.open(“win2.html”, “Window2”, “width=310,height=600,scrollbars=yes”);

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *