Javascript to show calculations based on 2 question

More
7 months 3 weeks ago - 7 months 3 weeks ago #149310 by mumbix
mumbix created the topic: Javascript to show calculations based on 2 question
Hi im fairly new to coding java queries to lime survey and wanted to know how i could multiply Q1 by Q2 using java script( both list radios)

so far i have tried this script in pentaho and seems to give the desired results but limesurvey is not having any of it pleasehelp...
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
var Q2 = {INSERTANS:86119X5228X47098};
var Q3 = {INSERTANS:86119X5228X47080};
var  Cost = '' ; 
 
if (Q3 == '25% discount so £14.85 for one a year subscription (UK)' && Q2 != '' || Q2 != null || Q2 !=  'Error(86119X5228X47098)') {
    Cost = (14.85 * Q2);
}	else if (Q3 == '25% discount so £28.00 for a two year subscription (UK)' && Q3 != '' || Q3 != null && Q2 != ''|| Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    Cost = (28 * Q2);
}	else if (Q3 == '25% discount so £20.25 for one a year subscription (ROW)' && Q3 != '' || Q3 != null && Q2 != '' || Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    Cost = (20.25 * Q2);
}	else if (Q3 == '25% discount so £38.00 for a two year subscription (ROW)' && Q3 != '' || Q3 != null && Q2 != '' || Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    Cost = (38 * Q2);
} 	else if (Q3 == '10% discount for a 1 years subscription is £24.30 (ROW) PROMO- ENG25' && Q3 != '' || Q3 != null && Q2 != ''|| Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    Cost = (24.30 * Q2);
}	else if (Q3 == '10% discount for a 2 years subscription is £33.75 (UK) + a free Calendar PROMO- ENG25' && Q3 != '' || Q3 != null && Q2 != '' || Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    Cost = (33.75 * Q2);
}	else if (Q3 == '10% discount for a 2 years subscription is £45.90 (ROW)' && Q3 != '' || Q3 != null && Q2 != ''|| Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    Cost = (45.90 * Q2);
}	else {
    Cost = (17.82 * Q2);
}
 
var Q1 = {INSERTANS:86119X5228X47079};
var  DDCost = '' ;
 
if (Q1 == 'Half price direct debit offer £8.50 for the first year and £17 yearly thereafter (UK) PROMO- ENGLA' && Q2 != '' || Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
	DDCost = (8.50 * Q2);
}	else if (Q1 == 'Half price direct debit offer Overseas £12.50 for the first year and £25.00 annually thereafter (ROW) PROMO - ENGLA' && Q2 != '' || Q2 != null || Q2 !=  'Error(86119X5228X47098)'){
    DDCost = (12.50 * Q2);
}	else {
    DDCost = (2.10 * Q2);
}
 
var  DDCost = '' ;
 
if ({INSERTANS:86119X5228X47079} == 'Half price direct debit offer £8.50 for the first year and £17 yearly thereafter (UK) PROMO- ENGLA' && {INSERTANS:86119X5228X47098} != '' || {INSERTANS:86119X5228X47098} != null || {INSERTANS:86119X5228X47098} !=  'Error(86119X5228X47098)'){
	DDCost = (8.50 * {INSERTANS:86119X5228X47098});
}	else if ({INSERTANS:86119X5228X47079} == 'Half price direct debit offer Overseas £12.50 for the first year and £25.00 annually thereafter (ROW) PROMO - ENGLA' && {INSERTANS:86119X5228X47098} != '' || {INSERTANS:86119X5228X47098} != null || {INSERTANS:86119X5228X47098} !=  'Error(86119X5228X47098)'){
    DDCost = (12.50 * {INSERTANS:86119X5228X47098});
}	else {
    DDCost = (2.10 * {INSERTANS:86119X5228X47098});
}
 
var Direct_Debit_Cost = document.createTextNode(DDCost);
var Pre_pay_Cost = document.createTextNode(Cost);
 
});
</script>
Last Edit: 7 months 3 weeks ago by DenisChenu. Reason: [code]

Please Log in to join the conversation.

More
7 months 3 weeks ago #149336 by DenisChenu
DenisChenu replied the topic: Javascript to show calculations based on 2 question

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now