Good day,
I need to type in the form based on the selected checkboxes.
For example, check option one and the text "you selected option one" will appear.
I suppose it can only be done by javascript, but I'm not sure how to do it. I think I even saw how to do it in the forum, but I'm not sure about it and I can't find it.
thank you for answer
You could just have a piece of text, and use the field events of the checkbox to hide or show it.
Unfortunately, probably not. I need to display the sum of the checkboxes. See https://jmp.sh/QJlwFIr
Why did you tick the DOM Ready box? Untick that.
And I can't ssee if you've written the function name in the event properly screen shot just that
Any errors in console? Want to add a console.log('run', triggered); to the code too and see if it's being called?
index.php?option=com_chronoforms6&cont=manager&chronoform=platba:48 Uncaught ReferenceError: triggered is not defined
at myFunction (index.php?option=com_chronoforms6&cont=manager&chronoform=platba:48)
at String.<anonymous> (g2.forms.js:342)
at Function.each (jquery.min.js?2917fefbad69e07d4908b3748e702580:2)
at String.<anonymous> (g2.forms.js:340)
at Function.each (jquery.min.js?2917fefbad69e07d4908b3748e702580:2)
at Object.<anonymous> (g2.forms.js:236)
at Function.each (jquery.min.js?2917fefbad69e07d4908b3748e702580:2)
at HTMLInputElement.<anonymous> (g2.forms.js:128)
at HTMLFormElement.dispatch (jquery.min.js?2917fefbad69e07d4908b3748e702580:2)
at HTMLFormElement.v.handle (jquery.min.js?2917fefbad69e07d4908b3748e702580:2)
when I put the consolelog () function, nothing is written
if I shorten it to:
function myFunction {trigger} {
jQuery ('# change_div'). text ("value selected was");
}
, hence without triggered, so it works.
How do I get form field values in javascript?
sorry trigger and triggered should obviously match. Call them both the same thing.
code works correctly:
function myFunction {trigger} {
jQuery ('# change_div'). text ("value selected was" + trigger.val ());
}
But I need to display the sum of the checked boxes, how do I get these values in javascript?
Try
let total;
jQuery ('input[name="thenameyoucalledthecheckboxeswithoutthebrackets"]:checked).each(function() { total +=parseInt(this).val());});
Beyond that, try Google
there is some syntax error and I can't determine it
Braces do not match and there is only one apostrophe.
I don't know where to end it
"thenameyoucalledthecheckboxeswithoutthebrackets" is "voucher"
parseInt(this).val() should be parseInt(this.val()) , assuming of course that you're only using integers for your field values and not doubles / floats.
Don't log the whole function, put a log INSIDE the function.
I can't do everything for you buddy
I understand you can't do it for me, but I just can't get it working.
Alternatively, you can follow these steps
1) On Select, "Add To", leave value box blank, "total_calc"
2) On unSelect, "Subtract from", leave value box blank, "total_calc"
3) Add a hidden input named "total_calc" with id "total_calc"
4) Add a custom HTML section, with <div id="total_calc_display"></div>
5) Use a "calculator" widget. Use "total_calc" for the calculation field ids, and "total_calc_display" for the display div id (pretty simple)
And that should do it, no code. It will have it negative at the moment because there appears to be an error. You can swap subtract/add for now, but when Max updates it you'll have to change it back.
Thank you very much, this is already working OK.
I can make other necessary changes in javascript myself.
Unfortunately javascript is not my friend.