Adding javascript script to submit button in a Form
Hi,
I have an Umbraco form and I want to add a js script in order to be able to validate some html inputs that are dynamically created in js side. How can I do this? For now, I will try to add a function in the onclick event in "submitbtn" button, but not sure if this is the standard way or if there is a better way to do this. Thanks!
Yes, I added a function in the onclick event in "submitbtn" button, but not sure if this is the standard way or if there is a better way to do this.
Are you using forms in Umbraco 9? If that is the case, I made this:
//* Adds a listener to onclick event in order to be able to validate
//* data and prevent to submit the form in case data is missing.
const addSubmitOnClick = () => {
var formName = document.getElementsByName("FormName")[0].value;
if (formName == "Opportunity Page")
document.getElementsByName("submitbtn")[0].onclick = validateOpportunityRegistration;}
I have a field type that uses a js, then added that field type to the form and the code above to that js. You can return false in the function used to validate data (validateOpportunityRegistration in my case).
Note: addSubmitOnClick(); is called when the js script is loaded.
Adding javascript script to submit button in a Form
Hi, I have an Umbraco form and I want to add a js script in order to be able to validate some html inputs that are dynamically created in js side. How can I do this? For now, I will try to add a function in the onclick event in "submitbtn" button, but not sure if this is the standard way or if there is a better way to do this. Thanks!
Did you get any solution?
Yes, I added a function in the onclick event in "submitbtn" button, but not sure if this is the standard way or if there is a better way to do this. Are you using forms in Umbraco 9? If that is the case, I made this:
I have a field type that uses a js, then added that field type to the form and the code above to that js. You can return false in the function used to validate data (validateOpportunityRegistration in my case).
Note: addSubmitOnClick(); is called when the js script is loaded.
is working on a reply...