我正在尝试获取多个下拉字段的平均值,以生成客户调查的客户评级。我使用ProcessMaker构建了这个调查,但我似乎无法让javacript代码工作。该脚本仅执行最后一个else语句并显示“No Rating Available”
以下是脚本;
var A = getField("Service_Delivery").value;
var B = getField("OnTime_Delivery").value;
var C = getField("Feedback").value;
var D = getField("Resolution").value;
var E = getField("Repeat_Findings").value;
var F = getField("Attitude").value;
//var SumTotal = A + B + C + D + E + F;
//var RatingVal = SumTotal/6;
var RatingVal;
var Result = getField("Result").value;
Result = RatingVal;
for (i=0; i<=5; i++){
A.onchange = function() {
RatingVal = (A + B + C + D + E + F )/6;
Result.value = RatingVal;
};
B.onchange = function() {
RatingVal = (A+ B+ C + D+ E + F)/6;
Result = RatingVal;
};
C.onchange = function() {
RatingVal = (A + B + C + D + E + F)/6;
Result = RatingVal;
};
D.onchange = function() {
RatingVal = (A + B + C + D + E + F)/6;
Result = RatingVal;
};
E.onchange = function() {
RatingVal = (A + B + C + D + E + F)/6;
Result = RatingVal;
};
F.onchange = function() {
RatingVal = (A + B + C + D + E + F)/6;
Result = RatingVal;
};
}
//Result = changeValue("Result", RatingVal);
if (getField("Result").value==1) {
getField("Rating").value= "Service Not Rendered";
var show1= getField("Rating").value;
alert(show1);}
else if (getField("Result").value==2) {
getField("Rating").value="Unsatisfactory";
var show2= getField("Rating").value;
alert(show2);}
else if (getField("Result").value==3){
getField("Rating").value="Satisfactory";
var show3= getField("Rating").value;
alert(show3);}
else if (getField("Result").value==4){
getField("Rating").value="Very Good";
var show4= getField("Rating").value;
alert(show4);}
else if (getField("Result").value==5){
getField("Rating").value="Excellent";
var show5= getField("Rating").value;
alert(show5);}
else{
getField("Rating").value="No Rating Available";
var show6= getField("Rating").value;
alert(show6);}
请协助......
答案 0 :(得分:0)
您必须更新代码才能使其正常运行。您可以参考以下代码:
var RatingVal;
for (i=0; i<=5; i++){
getField("Service_Delivery").onchange = function() {
getval();
};
getField("OnTime_Delivery").onchange = function() {
getval();
};
getField("Feedback").onchange = function() {
getval();
};
getField("Resolution").onchange = function() {
getval();
};
getField("Repeat_Findings").onchange = function() {
getval();
};
getField("Attitude").onchange = function() {
getval();
};
}
function getval(){
var A = parseInt(getField("Service_Delivery").value);
var B = parseInt(getField("OnTime_Delivery").value);
var C = parseInt(getField("Feedback").value);
var D = parseInt(getField("Resolution").value);
var E = parseInt(getField("Repeat_Findings").value);
var F = parseInt(getField("Attitude").value);
var r = (A + B + C + D + E + F)/6;
RatingVal = parseInt(r);
}
function displayResult(){
changeValue("Result", RatingVal);
if (getField("Result").value==1) {
getField("Rating").value= "Service Not Rendered";
var show1= getField("Rating").value;
alert(show1);
}
else if (getField("Result").value==2) {
getField("Rating").value="Unsatisfactory";
var show2= getField("Rating").value;
alert(show2);
}
else if (getField("Result").value==3){
getField("Rating").value="Satisfactory";
var show3= getField("Rating").value;
alert(show3);
}
else if (getField("Result").value==4){
getField("Rating").value="Very Good";
var show4= getField("Rating").value;
alert(show4);
}
else if (getField("Result").value==5){
getField("Rating").value="Excellent";
var show5= getField("Rating").value;
alert(show5);
}
else{
getField("Rating").value="No Rating Available";
var show6= getField("Rating").value;
alert(show6);
}
}
getField("display").onclick = displayResult;
我已更正代码中的各种问题,因为代码无效。
请检查代码是否适合您。
希望这有帮助