Javascript in CFV7

cappleby 22 Jun, 2022
I'm trying to upgrade from V5 to V7 but the custom code I've created that uses javascript to total amounts entered in the form doesn't work. That element appears as an empty form with the javascript code in text form. I als ocan't see how to add in a custom code element into the actions on the form.
Colnem 22 Jun, 2022
Hi

Where do you write your javascript code?
Do you use a Javascript View or a HTML view?
cappleby 23 Jun, 2022
In CFv5 I use a custom code module. When the old orm was transferred to CFv7 it appeared as a custom code form at first bu it then disappeared. I then tried using a php module.
I'm not sure what a javascript view is. The code is:
<?php
JHtml::_('jquery.framework');
?>

var j = jQuery.noConflict();
j(document).ready(function(jQ) {
jQ('#subs').click(calc);
jQ('#subs1').change(calc);
jQ('#subs2').change(calc);
jQ('#donation').change(calc);
jQ('#total').click(calc);


function calc() {
var sum, sum1, sum2, sub, don;
sub = 0;
don = 0;
sum = 0;
sub = jQ('input[name=subs]:checked').val();
if(sub === undefined){sub = 0;}
don = jQ('#donation').val().replace(/\$/g, '');
if(don === ''){don = 0;}
sum1 = parseInt(sub);
sum2 = parseInt(don);
sum = (sum1 + sum2);
jQ('#total').val(sum);
}
});

But I've just noticed that javascript doesn't work in the free version which I was using to check whether I wanted to upgrade. Very annoying!
cappleby 23 Jun, 2022
I've just found the trial validation option and the javascript doesn't work. It just appears as code text on the top of the form. Any suggestions how I can make it work?
Colnem 23 Jun, 2022
Hi

For Joomla, you have to use a Javascript Element in View Section/Custom Code/Javascript

If you use JQuery, yo can try to check Add Inside domready event.
cappleby 23 Jun, 2022
I now have a javascript element just befoere the submit button with the above code. Insidedomready is selected but the javascript isn't working. Are element names different with CF7?
Colnem 23 Jun, 2022
I think that CF5 form are not fully compatible with CF7. Test with a new form including simple javascript like alert('OK'). This does work...
cappleby 23 Jun, 2022
Yes I can see that aa new form may run the javascript but I really don't want to have to recreate an entire form. The annoying thing is that the javascript appears in the html of the form page but it doesn't do anything.
You need to login to be able to post a reply.