RE: append to onclick in javascript.

Discussion in 'ASP .Net' started by =?Utf-8?B?UG9rZXJKb2tlcg==?=, Jun 23, 2006.

  1. 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!
    =?Utf-8?B?UG9rZXJKb2tlcg==?=, Jun 23, 2006
    #1
    1. Advertising

  2. i found it!!!

    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
    =?Utf-8?B?UG9rZXJKb2tlcg==?=, Jun 23, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    200,428
    Adrienne Boswell
    Jun 20, 2006
  2. HYRY
    Replies:
    10
    Views:
    584
    Bruno Desthuilliers
    Sep 26, 2007
  3. bob
    Replies:
    3
    Views:
    176
  4. Replies:
    2
    Views:
    240
  5. Replies:
    4
    Views:
    165
Loading...

Share This Page