function getRelativePosition(e) {
var canvas = document.getElementById("canvas-diagram");
var scroll = document.body.scrollTop;
if( typeof( canvas.offsetParent ) != 'undefined' ) {
for( var posX = 0, posY = 0; canvas; canvas = canvas.offsetParent ) {
posX += canvas.offsetLeft;
posY += canvas.offsetTop;
}
return {x: e.clientX - posX, y: e.clientY - (posY-scroll)};
} else {
return {x: e.clientX - canvas.offsetLeft, y: e.clientY - (canvas.offsetTop-scroll)};
}
}
Get Relative Position of Mouse-Click in Canvas
31 08 2009Comments : 3 Comments »
Categories : Canvas, HTML5, Javascript
Email Address
25 03 2008var reg
= new
RegExp(‘^([a-zA-Z0-9_\\.\\-])+\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$’);
Comments : Leave a Comment »
Categories : Javascript, Regular Expression
Launch Website & Add Text Into Textbox
1 11 2007tell application "Safari"
--activate to bring Safari to the front--
activate
try
--check if Safari is already open --
set currentDoc to the document of window 1
on error NSReceiverEvaluationScriptError
set currentDoc to make new docuent
end try
set the URL of currentDoc to "http://www.google.com"
-- or use--
open location "http://www.google.com"
--delay for page to load--
delay 2
--use javascript to enter text into textbox
set thisscript to "document.forms[0].q.value='applescript';"
do JavaScript thisscript in document 1
end tell
Comments : Leave a Comment »
Categories : AppleScript, Javascript
Select 2nd Item In Listbox
27 09 2007form.listboxname.options[1].selected = true;
Comments : Leave a Comment »
Categories : Javascript
Javascript Alert Form Bean
4 09 2007<logic:notEmpty name="LoginForm" property="javascriptAlertMsg">
<script>alert('<bean:write name="LoginForm" property="javascriptAlertMsg"/>')</script>
</logic:notEmpty>
Comments : Leave a Comment »
Categories : Javascript, Struts
Javascript Alert Messages From Message Resource
4 09 2007alert('<bean:message key="MSG001"/>');
Validation Message:
var fieldname = '<bean:message key="fieldname.amount"/>';
var errorMsg = '<bean:message key=" errors.float" arg0="'+fieldname+'"/>';
alert(errorMsg);
In Message Resource:
MSG001 Hello world!
fieldname.amount Payment Amount
errors.float {0} is not a float
Comments : 6 Comments »
Categories : Javascript, Struts
Call Struts Validation Using Javascript
29 08 2007if(validateNameOfForm(document.forms[0])) {
document.forms[0].submit();
}
Comments : Leave a Comment »
Categories : Javascript, Struts
2 Decimal Floats
16 08 2007var regex = new RegExp(‘^[0-9]+(\.[0-9]{0,2})?$’);
Comments : Leave a Comment »
Categories : Javascript, Regular Expression
replaceAll String
14 08 2007replace all commas with whitespace
var firstName ="John, Doe";
var formattedName= firstName.replace(/,/g,' ');
Comments : Leave a Comment »
Categories : Javascript, Regular Expression