TroubleShooter Posted October 10, 2018 Report Share Posted October 10, 2018 Hi there, I have a Submission Form DataPage and I wanted to like count the number of options in a Dropdown field. I would be using that for division as I wanted to make a report on statistics. I already have some JavaScript working but the problem is, it doesn't work on Dropdowns with more than 100 options. document.addEventListener("DataPageReady", function() { ... var count = document.querySelector('[id=*InsertRecordCategory]').length; console.log(count); ... }) What's weird is that it returns a number (e.g. 7) when less than 100 or 0 when greater than 100 or so. Hope someone can help. Quote Link to comment Share on other sites More sharing options...
DefinitelyNot31337 Posted October 10, 2018 Report Share Posted October 10, 2018 Hello @TroubleShooter, The most likely reason why this happens is that DataPageReady fires when the DataPage DOM has finished loading, and a Dropdown with a lookup table loads only after its part in the DOM is loaded. Performance-wise, if the lookup takes a tiny second to load, it catches up before the DataPageReady event is fired. Otherwise, the variable count just evaluates to 0; A workaround I can suggest is to add a listener to the Dropdown. It should look something like: var count; var doc_v1 = document.querySelector('[id=*cbParamVirtual1]') doc_v1.onchange = function() { count = this.length; console.log(count); } Verified that this works on Single Record Update DP, Details DP, and Details drilldown too. Just be mindful on how you reference your elements. (Because, Caspio Elements Naming Convention) Might work on Inline Insert/Edit too but would need a few additions/modifications to the code. Hope this helps. Regards, DN31337 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.