Solved

Remove item on an onclick event

Posted on 2008-10-28
9
545 Views
Last Modified: 2012-06-21
IE7..
CRM 4.0..
Javascript..

I have an object with an onclick event that I want to remove. The onclick is set within existing CRM code. I want to replace it with my own event.

However, I have the assumed method..

crmForm.all["ts_addressesid"].detachEvent("onclick", openlui);  

..but this doesnt seem to do anything. One thing to note is that the function openlui is declared in an external file.

Any help is most appreciated!
0
Comment
Question by:djdidge
  • 6
  • 3
9 Comments
 
LVL 4

Expert Comment

by:gregowens
ID: 22820945

crmForm.all["ts_addressesid"].onclick = null;

Open in new window

0
 
LVL 2

Author Comment

by:djdidge
ID: 22821010
hi greg,

That didnt work..

Cheers
0
 
LVL 2

Author Comment

by:djdidge
ID: 22821274
the onclick is not visible in the html, i assume some wizardry has covertly attached the openlui function somehow...

Basically when i click the said image object, i get a crm lookup popup. That is what im trying to stop.
0
 
LVL 4

Expert Comment

by:gregowens
ID: 22821354
What are you trying to acheive for the end user? Would setting the the field to disabled or read-only not be an option instead? At least it would be "supported".
 

crmForm.all.ts_addressesid.disabled = true;

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Accepted Solution

by:
gregowens earned 95 total points
ID: 22821392
Incidentally, the reason the original code doesn't work (hadn't realised it was the built-in lookup function you were looking to disable) is because the function is not attached to the onclick event of the ts_addressesid object, rather it is attached to a SPAN tag within the control. Manipulating the DOM at that level is *not* the way to go ;)
 
 
0
 
LVL 2

Author Comment

by:djdidge
ID: 22821396
I need to replace the event with my own... the image button is part of a crm lookup field, i need to retain the control but fire a different event when clicking the image.

I have sucessfully added my own event using:

crmForm.all["ts_addressesid"].attachEvent("onclick", test);

that works fine and fires the function "test".

However, after that, the other event fires.

0
 
LVL 2

Author Comment

by:djdidge
ID: 22821543
i know its not CRM supported, but to be honest, most of the customisations we're having to do arent!... i cant find the said span... but i have found the CRM code that sets it..

taken from lookup.js in the CRM deployment

------------------------------------------
 
 

function BuildFieldSpan(lookupField, lookupItems)

{

var html = "";

var len = lookupItems.items.length;

for (var i = 0; i < len; ++i)

{

var item = lookupItems.items[i];
 

html += (i > 0 ? " " : "");
 

var e = parent.document.createElement("SPAN");
 

e.className	= "ms-crm-Lookup-Item";

e.oid		= item.id;

e.otype		= item.type;

e.innerHTML	= item.html;

e.onclick	= "openlui();";
 

html += e.outerHTML;

}

if (html.length == 0)

{

html = "&nbsp;";

}

return html;

}

Open in new window

0
 
LVL 2

Author Comment

by:djdidge
ID: 22821573
scratch that... ive found it in the source html, but strangely, its not findable using the IE Dev toolbar!
0
 
LVL 2

Author Comment

by:djdidge
ID: 22821599
I am going to manually re-write the html on the fly to remove it! shhhh! ;)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now