Buy Now
Sign in

executing javascript function in a load event

tshirley , June 05 2021, 07:35
tshirley 327
June 05 2021, 07:35 #396614
I have a form where a javascript function executes when a field is changed: so, when a user enters a value into Field 1 or Field2, a js function is called as an Event in the Form, performs a calculation and places the result in Field 3, using the On Change trigger. Works well.
However when I populate the form from a database table or external file, the fields are filled but the js function is not run unless the user changes one of the input fields after loading.
I did try the Not empty trigger but this did not work either.
Is there a way that I can get CF6 to execute the js function when the fields are populated from the database? Preferably a way to run it when triggered by the data being loaded into the field.
GreyHead 65
June 05 2021, 08:44 #396617
Hi Tim,
You probably need to run your function when the page loads. See this StackOverFlow page for several ways to do this.
If you'd like to buy me a coffee or two, thank you very much
tshirley 327
June 05 2021, 12:05 #396620
Thanks Bob,
It looks like a good way to go, but I am not certain how that translates into a typical CF6 form.
If I wanted to use one of the solutions here, say
window.onload = function ...
How would I do it? In a custom code after the Display Form?
healyhatman 9
June 06 2021, 11:15 #396622
There's custom JS code blocks in CFv6, and there's a big giant "on page load" checkbox.
Web developer at - I DO NOT work for ChronoEngine!
Professional Work:
Custom CF / CC Plugins and Extensions:
Pigna 63
June 10 2021, 13:29 #396652
I had the same problem on a CF7 form and the option "on page load" / "add inside domready event" don't work.
So i've put an img at the end of the page with a transparent 1x1 pixel image that call the function:
<img src="images/pxl.png" alt="" onload="myFunction()" />
and it's work.