Dave Merrill
03/25/2022, 7:33 PMdocument.getElementById('incidentsourceid_12').dispatchEvent(new Event('click'));
But that doesn't run the handler (or toggle the checkbox, which is fine).
This does work, but eval is more or less against my religion:
eval(document.getElementById('incidentsourceid_12').getAttribute('onclick'));
Related, is there a general js Slack channel?Patrick S
03/25/2022, 7:41 PMDaniel Mejia
03/25/2022, 7:42 PMDaniel Mejia
03/25/2022, 7:43 PMAdam Cameron
https://i2.paste.pics/ec0298501f33eda7bc2deb0471c63136.png▾
Dave Merrill
03/25/2022, 7:52 PMAdam Cameron
showHideStuff
is what works as a click event handler to do the needful, why don't you just call showHideStuff
?Dave Merrill
03/25/2022, 8:35 PMshowHideStuff()
is really more like this:
"multi_ifothershowhide('transportedid', 1, 'transportedbyid,transportdestinationid');multi_ifothershowhide('transportedid', 2, 'transportedwhynotid');"
The closest I've come so far to running that without repeating it, and doing the same for all the other similar fields on the page, is the eval(getAttribute('onclick')) version. The code knows which fields I'm concerned with, so I just wrote a function to get the onclick and run it, I just don't love it.
How are you folks handling this sort of thing?Daniel Mejia
03/25/2022, 8:38 PM<cfoutput><script>setInitialState(#serializeJson(FormConfiguration)#);</script>
the javascript method setInitialState()
takes that object and calls all your inner show/hide methods.David Buck
03/25/2022, 8:41 PMmyForm.myInputElement.onclick()
, replacing myForm
with the value of the name
attribute of your form element, and myInputElement
with the value of the name attribute of the input element whose onclick functions you want to run.Dave Merrill
03/25/2022, 9:05 PMif (changingField.tagName === 'SELECT')
changingField.onchange();
else
changingField.onclick();
Just goes to show, asking dumb questions helps!David Buck
03/25/2022, 9:37 PMelement.addEventListener()
, those event handlers won't execute.Dave Merrill
03/25/2022, 9:39 PM