Calculate modal score (Overall Rating) from multiple option button controls - InfoPath Dev
in

InfoPath Dev

Calculate modal score (Overall Rating) from multiple option button controls

Last post 08-27-2009 12:24 PM by GaryFuller. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-26-2009 07:31 AM

    Calculate modal score (Overall Rating) from multiple option button controls

     Greetings all,

    I am new to InfoPath/SharePoint development, coming from Lotus Notes background. I have a performance appraisal application to redevelop in InfoPath for WIndows SharePoint Services 3.0. I will be using ShareVis to publish InfoPath forms to WSS as web browser forms.

    I have 8 radio buttons, each with 4 choices (E,M,N,B). I need to calculate one Overall Rating Score from these (E,M,N, or B). The way I did it in Lotus Notes/Domino was with Javascript, using  a function and swich statements, like so:

    function modalscore() {
    var f = document.forms[0]
    var done = false;
    var Ecount = 0;
    var Mcount = 0;
    var Ncount = 0;
    var Bcount = 0;
        //validate the field --------------------------------rbQ1
    for (index = 0; index < doc.rbQ1.length; index++)
        {
            if (doc.rbQ1[index].checked)
            {
                done = true;
                var Q1=doc.rbQ1[index].value;
            }
    }
        if (! done)
        {
            alert("Please select a Rating (E,M,N, or B) for Job Factor 1.");
            doc.rbQ1[0].focus();
            return false;    //to stop further processing
        }
    done = false;

    (etc....)

    // Calculate modal score with switch statement.       
    switch (Q1) {
    case "E" :
        Ecount += 1;
        break;
    case "M" :
        Mcount +=1;
        break;
    case "N" :
        Ncount += 1;
        break;
    case "B" :
        Bcount += 1;
        break;
    default : 

    (etc.....)

     and then some IF/ Else statements, like these:

    if ((Ecount > Mcount) && (Ecount > Ncount) && (Ncount != ""))
    {
        doc.txtOverallRating.value = "M";
    }
    else if ((Bcount > Ecount) && (Bcount > Mcount) && (Bcount >= Ncount))
    {
        doc.txtOverallRating.value = "B";   
    }
    else if ((Mcount = Bcount) && (Mcount > Ecount) && (Mcount >= Ncount))
    {
        doc.txtOverallRating.value = "N";
    }
    else if ((Ecount > Mcount) && (Ecount > Ncount) && (Ecount > Bcount))
    {
        doc.txtOverallRating.value = "E";   
    }

    (etc...)

    and calling the function with a 'Compute' button using:

    modalscore();

     I'm not sure how much (if any) code behind I'll be able to use (these will be web-enabled forms, but not using Forms Services), so I'd like to use the built-in InfoPath devices as much as possible, hopefully with Rules.

    Any helpful ideas would be much appreciated! Coding solutions also welcome!

    - Gary Fuller

  • 08-27-2009 12:24 PM In reply to

    Re: Calculate modal score (Overall Rating) from multiple option button controls

     Okay, I figured it out myself. I used Rules in the 'Compute' button to set the field value in the Overall Rating field, first to a number total. (I gave number values to each radio button option like so: E=4, M=3, N=2, B=1.)

    If not a manager, (rbQ6, rbQ7, rbQ8 = ""), then use the total of option buttons 1-5. The number values correspond to predetermined letter values: 18-20="E", 13-17="M", etc. If a manager, (rbQ6,rbQ7,rbQ8 !=""), then use the total of option buttons 1-8. The number values correspond to different letter values: 29-32="E", 21-28="M", etc.

    Then I added rules that set the letter value of the Overall Rating back from the number according to the previous conditions. Works like a charm! Thanks to all who viewed the query. Maybe this will help someone in the future. -GF

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.