onchange event fails to fire when number of items in a lookup column exceed 19
Hi folks,I am facing a peculiar problem related to lookup columns in sharepoint 2007. I have a listform webpart in which there is a lookup column based on a list. I have a javascript that fires on the "onchange" event of this column. This was working fine untill now. Recently I noticed that the "onchange" event has stopped firing. I did some investigation and came to a conclusion that if I limit the number of items in the list to below 19, the "onchange" event starts firing again, the moment the items become 20 or more in number I start seeing the same behaviour. I even installed the SP2 for sharepoint 2007 and wss v3 hoping that it may resolve the problem I am facing. Has anybody experienced such behaviour? Can somebody throw some light on this, am I missing something?
September 11th, 2009 5:24pm

SharePoint uses a different control once you hit 20 options. It's sort of a hybrid input/select.I'm not sure what you are trying to do with your dropdown, but you might want to take a look at our jQuery Library for SharePoint Web Services. In it, we have a function called $().SPServices.SPCascadeDropdownswhich lets you have the selection in one dropdown change the available options in another. At the very least, you can see in the library how we handle the 20+ control.If the libriary doesn't do something you are looking for, let me know and we might be able to add it.M.Marc D Anderson - Sympraxis Consulting LLC - Marc D Anderson's Blog - @sympmarc
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2009 5:59pm

If the default behaviour of a control changes when a certain condition is met and you have to write custom code to make it behave the same way as it did originally. I would call it customization. I dont know how you feel this is not customization.
September 18th, 2009 5:33pm

I've never seen any "official" documentation on this. As with many other SharePoint things, the best stuff is in the blogosphere.M.Marc D Anderson - Sympraxis Consulting LLC - Marc D Anderson's Blog - @sympmarc
Free Windows Admin Tool Kit Click here and download it now
September 18th, 2009 5:40pm

For those people who are facing the same problem as me I will give some background. When you create a lookup column in sharepoint in a list, while rendering on the browser it gets converted to a "Select" HTML control. Now here is the catch, if the number of "options" exceeds 19 sharepoint starts rendering the same control as a textbox control (<input type="text" >). I looked into the HTML source of the rendered page and realized that the combo box that you see for lookups that have > 19 options, is actually a combination of a textbox and an image. (that is the reason a lookup with < 19 options looks different from one with > 19 options). Internally the options are all stored with the textbox control as an attribute called "choices". On clicking on the image that is part of the lookup control, the function "ShowDropdown()" is called with the id of the textbox passed as an input parameter. There is a javascript file called Core.js which holds all these functions. You can search for this file on the sharepoint server and look at the code inside.Conclusion: 1. The following function must be familiar to a lot of you'll. It gives us a handle to the control. function getField(fieldType,fieldTitle) { var docTags = document.getElementsByTagName(fieldType); for (var i=0; i < docTags.length; i++) { if (docTags[i].title == fieldTitle) { return docTags[i] } } } 2. I use the following lines of code to determine if the control is a lookup with < 19 options or one with > 19 options and accordingly set my function to be called either on "onchange" event or on "onblur" event if(getField('select','Role') != null){ //incase of lookup having < 19 options if(getField('select','Role').type == 'select-one'){ getField('select','Role').onchange = function() {syncDropDowns()}; } }else if(getField('input','Role') != null){ //incase of lookup having > 19 options if(getField('input','Role').type == 'text'){ getField('input','Role').onblur = function() {syncDropDowns()}; } } I realized that the "onchange" event does not fire in a textbox control when you change the value programatically. So I used the onblur event instead. When you select a value from the lookup the value of the textbox changes, but in order for my function to be invoked I need to force the onblur event to happen. I noticed that in the Core.js file there is a function called "SetCtrlFromOpt" which is the last one to be invoked among a series of other functions. So I created my own function with the same name and from within that function I called the original function. After invoking the original function I added the code that I wanted (to force the "onblur" event. //Code to take care of lookup having more than 19 items //*********************************************************** var orgSetCtrlFromOpt = SetCtrlFromOpt; SetCtrlFromOpt = function(ctrl, opt){ orgSetCtrlFromOpt(ctrl, opt); //invoke the original SetCtrlFromOpt() function var id = ctrl.id window.setTimeout('ctrlSetFocus("'+id+'")', 100); } function ctrlSetFocus(id){ document.getElementById(id).focus(); document.getElementById(id).blur(); } //*********************************************************** So now my "syncDropDowns()" function gets invoked irrespective of the fact whether the lookup column has < 19 options or > 19.
September 23rd, 2009 10:53am

Hi, We are facing a unique problem with jQuery, and I am using your SPServices library GetListItems method. I have a managed meta data column, which is the SharePoint field type equivalent to SPFieldTaxonomyFieldType, I wish to call the change event on this particular field and fire a jQuery function which uses the GetListItems and Query tags to find to populate my other textbox field in the same NewForm based on the managed meta data column. For eg: Skills is a managed metadata column and the associated text box is the Technology which has a 1-Many mapping with each other. I have tried using all the methods like change, blur, onchange etc to capture the change of the particular event, my code looks like this: <script src="http://smt-spvm32/sites/bas/Shared%20Documents/jquery-1.4.2.min.js" type="text/javascript"></script> <script language="javascript" src="http://smt-spvm32/sites/bas/Shared%20Documents/jquery.SPServices-0.5.5.min.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> jQuery.noConflict(); jQuery(document).ready(function($){ $("#ctl00_m_g_b4699157_88c9_42cd_8f43_36d4b8d78aa5_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl02editableRegion").change(function() { alert("Something has changed"); //other code follows... }); }); </script> Can you help in this regards. Mehul Bhuva My daily learnings on Sharepoint, InfoPath, Nintex workflows - http://www.sharepointfix.com
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2010 11:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics