Skip Navigation

[Resolved] How to add JS (JavaScript) code to Content Templates, or CRED forms?

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can we add Custom code (JS, scripts) to CRED forms or Views or Content Templates?

Solution:
If you want to add JS to CRED forms or Content Templates you can do so in their respective JS Editors (below each HTML editor).
The JS Code you add must use "jQuery" namespaces:
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/#achieving-great-results-with-little-coding-by-using-jquery

In Views, you as well have a button in the JS editor, so to hook your code to AJAX events of the View.

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 1 month ago.

Assisted by: Beda.

Author
Posts
#619196

Tell us what you are trying to do?
Following steps from this ticket: https://toolset.com/forums/topic/cred-for-woocomerce-similar-to-field-factory/

I have created a cred form and displaying it inside a 'content template' for a woocomerce product. I need a jquery to execute, and I would prefer it to only load when they are on this page. I have it working on my personal js file, but when I attempt to place it within the 'content template' wp-types page it does not work (no errors showing on the page).

(function($) {
$(window).load(function() {
$( ".single_add_to_cart_button" ).click(function() {
$( "#cred_form_198_1.cred-keep-original" ).submit();
});

})(jQuery);

#619329

If you want to add JS to CRED forms or Content Templates you can do so in their respective JS Editors (below each HTML editor).

FOr CRED Forms you do that when editing CRED Forms and for Content Templates when you edit Content Templates.

The JS Code you share will not work in WordPress because it uses a non-standard namespace "$".
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/#achieving-great-results-with-little-coding-by-using-jquery

I am also not exactly sure what the code should achieve - if you can explain that maybe I can come up with a solution or more information on how to achieve it.

The ticket you linked to is not related to any JS - it's about charging with products on a Form (it uses cred_commerce_add_product_to_cart hook, which is a CRED commerce feature, and not a JS code)

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.