View Full Version : help with javascript syntax error

01-07-2009, 01:24 PM
objLinks[i].onclick = new Function( "event", "return false;" + objLinks[i].onclick.toString().getFuncBody() );

Im new to javascript and have a functions that returns ans error onthe above line. The error is simpy - syntax error: return false;)

can anyone see whats wrong?

many thanks

01-07-2009, 04:07 PM
I could be wrong but I don't think getFuncBody is native to Functions.

You can write your own functional code like this:

function getFuncBody(ref)
var f = ref.toString().replace(/[^{]+{/,"");
return f.substring(0,f.length-1);

Or add it via Function.prototype for OO Code.

But since you're returning false before running the original onclick code, it seems to me you're simply wanting to disable the onclick handler which you can do by simply deleting it altogether:

element.onclick = "";

Or stick to this thread here: http://www.codingforums.com/showthread.php?t=155562

EDIT: Just realized you posted both threads - please stick to one thread at a time.