Buy Now
Sign in

javascript text display

ernst@volny.cz , January 08 2020, 19:35
healyhatman 8
January 09 2020, 23:49 #390645
Don't log the whole function, put a log INSIDE the function.
I can't do everything for you buddy
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 12 2020, 21:02 #390686
I understand you can't do it for me, but I just can't get it working.
healyhatman 8
January 12 2020, 21:37 #390688
let total;
jQuery('input[name="voucher"]:checked').each(function() {
total += parseInt(this.val());
console.log('Run!', this.val());
}));

console.log('Finished running');

jQuery('#theIDofthedivwhateveritwasyoucalledit').text('$' + total);
Do that inside the function and if it doesn't work have a look at the console and let me know.
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 12 2020, 23:04 #390692
I'm unhappy, it still doesn't work for me.
I found you had an extra bracket there, but that wasn't it.
the code is:
function myFunction(trigger) {
let total;
jQuery('input[name="voucher"]:checked').each(function() {
total += parseInt(this.val());
console.log('Run!', this.val());
});

console.log('Finished running');

jQuery('#total').text('$' + total);
}
but this part does not run (it is not written to the log)
   total += parseInt(this.val());
console.log('Run!', this.val());
it doesn't write any error in console, it writes only "Finished running"
healyhatman 8
January 13 2020, 00:31 #390694
 1
function myFunction(trigger) {
console.log('Start');
total = 0;
jQuery('input[name^="voucher"]:checked').each(function() {
let currentVal = jQuery(this).val();
total += parseInt(currentVal);
});
console.log('Total: ' + total);
console.log('End');
jQuery('#div_id_goes_here_with_hash_symbol_in_front').text('$' + total);
}
That code there works for me, if displaying a numerical total is what you're trying to do.

If you're trying to literally just display text saying what you've selected (which.... why?) then you change the total += line to something like
total += currentVal + "<br>";
Which will put each selection on a different line.
If you want anything more complicated, like IF (selected option A, C, D) THEN (display this message) ELSE (display some other message) then you'll either have to pay me or learn javascript. It's not super complicated, plenty of free basic learn to code things on 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
healyhatman 8
January 13 2020, 00:41 #390695
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.
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 13 2020, 08:11 #390701
Thank you very much, this is already working OK.
I can make other necessary changes in javascript myself.
Unfortunately javascript is not my friend.