RE: append to onclick in javascript.

G

Guest

ok, it is definately the string... because i convert the original onclick to
a string..

var a = objects[no].onclick;
var b = String(a)

objects[no].setAttribute('onclick', a);
//above works fine


objects[no].setAttribute('onclick', b);
//above doesn't work

If someone can help me work this out, I owe you bigtime!
 
G

Guest

i found it!!!

the key, was the "Function" function. It wraps a string variable in a
function, which works when assigned to an event (like onclick). here is the
final code, hope it helps someone in the future!

var a = objects[no].onclick; //set a to onclick event
var b = String(a); //translate a to string
a = b.substring(0, b.length - 16) + ';moveDiv(' + posX(objects[no]) + ',' +
posY(objects[no]) + ');';// append new section to onclick string
a = a.substring(22,a.length);//remove unwanted begining of event
objects[no].onclick = Function(a + "return false;");//translate a to
function and assign back to event
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top