Title: additional button created using html not allow onclick
Last modified: December 15, 2024

---

# additional button created using html not allow onclick

 *  Resolved [dmnvrse](https://wordpress.org/support/users/dmnvrse/)
 * (@dmnvrse)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/additional-button-created-using-html-not-allow-onclick/)
 * hi,
 * i’m trying to create additional button with onclick to call javascript using 
   html field, the onclick always being removed which is not flexible at all.
 * i tried to add event listener and notice the html keep being refresh/mutate as
   well cause the event listener removed. may i know why it is not allowed?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/additional-button-created-using-html-not-allow-onclick/#post-18199425)
 * Hello [@dmnvrse](https://wordpress.org/support/users/dmnvrse/)
 * Hope you are well and safe.
 * We don’t allow adding and running scripts in HTML field because of security reasons,
   the onclick easily can be used for XSS attacks so I wouldn’t suggest using it.
 * Its possible to change that behavior using the “wp_kses_allowed_html” hook that
   we are using for filtering the HTML input but I’m afraid I can’t provide you 
   any custom code because it is out of scope of our support.
 * The event listener should work you can target the form ID + your field class 
   or add a specific ID for your custom HTML code, I may be able help further if
   you share an example code.
 * Kind Regards
    Amin
 *  Thread Starter [dmnvrse](https://wordpress.org/support/users/dmnvrse/)
 * (@dmnvrse)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/additional-button-created-using-html-not-allow-onclick/#post-18199560)
 * I was using event listener initially and it doesn’t work due to the HTML div 
   keep changing when there is changes on other field, validation etc.
 * I’m targeting specific form ID + field class. the same script targeting button
   outside form was fine. but not the button created using HTML field. that’s why
   i thought of using onclick as last resort.
 * onclick might not be the best but i guess adding CSP header will make it safe?
   I’m not sure as I’m new in web development.
 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/additional-button-created-using-html-not-allow-onclick/#post-18200822)
 * Hello [@dmnvrse](https://wordpress.org/support/users/dmnvrse/)
 * I consulted with our developers about your issue, I’m afraid you can’t run a 
   function like this **onclick=”myFunction()** as I mentioned due to security reasons
   we have disabled it on form fields.
 * but you can do something like as an event listener:
    `document.getElementById('
   myBtn').onclick = myFunction;`
 * So when the user clicks on your button with myBtn ID, it will trigger another
   Javascript function and eventually run your code, since custom is out of scope
   I can’t provide an example. If you need further assistance, you’ll need to hire
   a developer to provide the required custom code for you. WordPress provides a
   jobs directory here [https://jobs.wordpress.net/](https://jobs.wordpress.net/),
   if you need further advice about it, feel free to email `wpsupport@incsub.com`.
 * **Subject: ATTN: WPMU DEV support – wp.org**
 * Kind Regards
    Amin
 *  Thread Starter [dmnvrse](https://wordpress.org/support/users/dmnvrse/)
 * (@dmnvrse)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/additional-button-created-using-html-not-allow-onclick/#post-18206578)
 * Thank you for keeping the plugin/web safe! a big lesson learned on XSS attack.
   i’ll close this.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘additional button created using html not allow onclick’ is closed to 
new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [dmnvrse](https://wordpress.org/support/users/dmnvrse/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/additional-button-created-using-html-not-allow-onclick/#post-18206578)
 * Status: resolved