Jquery Add dropdown values for a...

User 2685798 Photo


Registered User
5 posts

I got some of the code to work is there a way to get dropdown values to add up for a hidden field so I can pass the total.
I can see a selector value but when I try to add it up it concatenates instead of adding the values into a single value.
It also seems that the hidden field might only pull from before on the URL for when the page is hit to pass through and not from a field I have created in the html section.
Any info thanks - G
User 187934 Photo


Senior Advisor
18,836 posts
Online Now

Hi Glynn,
If you can share a link to your form I may be able to give some advice.;)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
https://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
https://progrower.coffeecup.com/shop/
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2685798 Photo


Registered User
5 posts

i have an html section near the submit
<style>
#item27, #item29, #item30, #item31,#item32,#item33{
visibility: hidden
}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script>
$("#docContainer").submit(function(){
var val1 = $("select[name=india1]").val();
var val2 = $("select[name=india2]").val();
var val3 = $("select[name=india3]").val();
var val4 = $("select[name=india4]").val();
var val5 = $("select[name=india5]").val();
var val6 = $("select[name=india6]").val();
var indiaTotal = $("#TotalHoursIndia").val();
var total = parseInt(val1) + parseInt(val2) + parseInt(val3) + parseInt(val4) + parseInt(val5) + parseInt(val6);
indiaTotal = total;
});
</script>
<input type="hidden" name="TotalHoursIndia" value="" id="TotalHoursIndia">



select values show up but cant get the value of the sum - basically trying to find the total hours of India added.
then pass the sum to the email...

http://fishbowl.coffeecup.com/forms/FishbowlDailyReport/

User 2685798 Photo


Registered User
5 posts

thank you in advance :cool:
User 187934 Photo


Senior Advisor
18,836 posts
Online Now

I do like seeing the actual form but this seems pretty straight forward and you've given me enough info to at least throw an example together.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
var jQ = $.noConflict(true);
// version 1
jQ(document).ready(function () {
jQ('select[name^="india"]').on('change', function() {
var sum = 0;
jQ('select[name^="india"] :selected').each(function() {
if(jQ.isNumeric(jQ(this).val())){
sum += Number(jQ(this).val());
}
});
jQ('input[name="TotalHoursIndia"]').val(sum);
});
});
</script>

Working here
http://ericrohloff.com/coffeecup/ccforu … alues.html
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
https://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
https://progrower.coffeecup.com/shop/
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2685798 Photo


Registered User
5 posts

Eric Rohloff - thanks so much - :cool::)

exactly what I was looking for. Not the best at Jquery = still learning.

G

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.