Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have been tasked with debugging custom javascript which was originally written for 2007 by a 3rd party vendor. The 2007 site has upgraded to 2010 and the javascript has stopped working.

The one bit which I can't seem to figure out fully is code which overwrites SetCtrlFromOpt. In 2007, this function would get called whenever the value of a lookup field was select (those with more than 20 elements).

In 2010 this method is never called and does not seem to exist at all in the core Sharepoint js. I was able to find _SetCtrlFromOpt, but this does not seem to get called either.

Does anyone know if there is some 2010 alternative to this function? There must be something called when the element is selected from the dropdown, to copy from the select to the input, but I'm having a hard time finding this event as this select seems to be created dynamically when the arrow is clicked.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I don't know what javascript is called when item is selected (I'll try to make some investigations later). But may be this trick can help you: when lookup renders as input, this input has optHid attribute. The value of the attribute is an id of hidden input, that tracks currently selected lookup id. You can try to attach onchange event to this hidden input, so when onchange will be fire, it will be mean that lookup's selected value changed.

edit
Yes, setup onchange is a bad idea, it will never fire. But _SetCtrlFromOpt is exactly yours function. This method fires every time when item selected in lookup. In some mystic reasons I can't debug it using IE developers tools (it simply not hit the breakpoint), but I verify it using this javascript (place it on your list form):

ExecuteOrDelayUntilScriptLoaded(function(){
      var oldset = _SetCtrlFromOpt;
      _SetCtrlFromOpt = function(ctrl, opt){
            alert("changed!");
            oldset(ctrl, opt);
       }
},"core.js"); 

_SetCtrlFromOpt declared in core.js, so we wait until it loaded and substitute with our function to check if it fires.

share|improve this answer
    
Thanks, I'll give that a shot. Though I suspect that the event will likely not fire as the value is changed through javascript. Unless Sharepoint explicitly fires it. –  James Montagne Jan 21 '12 at 0:46
    
_SetCtrlFromOpt is your function, please refer to my update. –  Kai Jan 21 '12 at 7:47
    
Thanks, I'll try it again on Monday. It didn't fire when I tried that but my guess is that something else was interfering. –  James Montagne Jan 22 '12 at 0:55
    
Turns out the part I was missing was the ExecuteOrDelayUntilScriptLoaded. In 2007 core.js is just included normally as a script. Apparently in 2010 it is delayed, causing my script to be run first. This did the trick. Thank you. –  James Montagne Jan 23 '12 at 15:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.