Get Relative Position of Mouse-Click in Canvas

31 08 2009

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)};
}
}

Advertisements




Email Address

25 03 2008

var reg

= new

RegExp(‘^([a-zA-Z0-9_\\.\\-])+\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$’);





Launch Website & Add Text Into Textbox

1 11 2007

tell 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





Select 2nd Item In Listbox

27 09 2007

form.listboxname.options[1].selected = true;





Javascript Alert Form Bean

4 09 2007

<logic:notEmpty name="LoginForm" property="javascriptAlertMsg">
<script>alert('<bean:write name="LoginForm" property="javascriptAlertMsg"/>')</script>
</logic:notEmpty>





Javascript Alert Messages From Message Resource

4 09 2007

alert('<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





Call Struts Validation Using Javascript

29 08 2007

if(validateNameOfForm(document.forms[0])) {
document.forms[0].submit();
}