Buy Now
Sign in

javascript text display

ernst@volny.cz , January 08 2020, 19:35
E
ernst@volny.cz 113
January 08 2020, 19:35 #390598
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
healyhatman 8
January 08 2020, 22:21 #390603
You could just have a piece of text, and use the field events of the checkbox to hide or show it.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 08 2020, 23:30 #390607
Unfortunately, probably not. I need to display the sum of the checkboxes. See https://jmp.sh/QJlwFIr
healyhatman 8
January 08 2020, 23:48 #390608
Javascript block.
function myFunction() {
// Sum the values
jQuery('#div_id').text('$' + summed_value);
}
Set the on change field event to "function" and in the value (not the identifier) put myFunction
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 09:17 #390613
I'm sorry, but I can't finish it.
What does myFunction call?
I need her to call after every checkbox entry.

Can you please give me an example?

Now I have it like this:
screencapture-terasauprince-uvirt89-active24-cz-administrator-index-php-2020-01-09-10_16_33.png
healyhatman 8
January 09 2020, 11:48 #390619
Your jQuery code is wrong, that would replace the text inside ALL 'p' elements with what you've written. Obviously no good.
In the field's Events tab, do triggering event "change", triggered action "function", affected elements "myFunction"
Change the text for change to
<div id="change_div">text for change</div>
Change the javascript code to
function myFunction(trigger) {
jQuery('#change_div').text("value selected was " + triggered.val());
}
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 18:59 #390623
Thank you for the instructions, but it still doesn't work for me.
Perhaps I did everything you wrote, but it seems to me that javascript function will not be called
see screencapture-terasauprince-uvirt89-active24-cz-administrator-index-php-2020-01-09-19_58_01.png
healyhatman 8
January 09 2020, 19:08 #390624
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
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 19:12 #390626
I canceled DOM Ready, but it still doesn't work
javascript.png
Attachments
javascript.png
javascript.png
(47.83 KiB)
79 Downloads/Views
healyhatman 8
January 09 2020, 19:15 #390627
Any errors in console? Want to add a console.log('run', triggered); to the code too and see if it's being called?
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 19:17 #390628
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)
E
ernst@volny.cz 113
January 09 2020, 19:18 #390629
when I put the consolelog () function, nothing is written
E
ernst@volny.cz 113
January 09 2020, 19:21 #390630
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?
healyhatman 8
January 09 2020, 19:26 #390631
sorry trigger and triggered should obviously match. Call them both the same thing.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 19:27 #390632
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?
healyhatman 8
January 09 2020, 19:37 #390633
Try
let total;
jQuery ('input[name="thenameyoucalledthecheckboxeswithoutthebrackets"]:checked).each(function() { total +=parseInt(this).val());});
Beyond that, try Google
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 20:04 #390636
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"
E
ernst@volny.cz 113
January 09 2020, 20:29 #390638
I modified it to not report syntax error, but it returns an object instead of a value:
console.log(jQuery ('input[name="voucher"]:checked').each(function() { total +=parseInt(this).val()}));
console log is:
  1. a.fn.init&nbsp;[selector: "input[name="voucher"]:checked", prevObject: d.fn.init(1), context: document]
  2. selector:&nbsp;"input[name="voucher"]:checked"
  3. length:&nbsp;0
  4. prevObject:&nbsp;d.fn.init&nbsp;[document,&nbsp;context:&nbsp;document,&nbsp;selector:&nbsp;""]
  5. context:&nbsp;document
  6. __proto__:&nbsp;Object(0)
healyhatman 8
January 09 2020, 20:34 #390641
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.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
ernst@volny.cz 113
January 09 2020, 21:18 #390642
I have: console.log(jQuery ('input[name="voucher"]:checked').each(function() { total +=parseInt(this.val())}));
but the result doesn't write it to the console, just the object:
  1. a.fn.init&nbsp;[selector: "input[name="voucher"]:checked", prevObject: d.fn.init(1), context: document]
  2. selector:&nbsp;"input[name="voucher"]:checked"
  3. length:&nbsp;0
  4. prevObject:&nbsp;d.fn.init&nbsp;[document,&nbsp;context:&nbsp;document,&nbsp;selector:&nbsp;""]
  5. context:&nbsp;document
  6. __proto__:&nbsp;Object(0)
I can't handle it without you