Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Constant Sum CBC

We are programming a Constant Sum CBC wherein we want sum of all responses to be atleast a number piped in from previous question. But sum can accept answer more than that.

For eg. Q1. We are asking how many pcs of X you buy in last 30 days, response is 500. I am using this response in CBC.

We use functionality of "Allowable input range" and put Amount above Total Value as 999.

Now, if I put values as 400 and 101 in two boxes, it works fine. but if we put 501 in one box, it doesn't work. Software restrict max value in 1 box as 500.

Can you please suggest some resolution
asked Mar 4, 2016 by Saurabh Aggarwal Gold (29,615 points)

2 Answers

0 votes
Hi Saurabh,

I created a numeric question 'n' for my piped in value and then made these changes to my Chip Allocation settings:

Total: 999
Amount below the Total Value: [% 999-n %]
Amount above the Total Value: 0

Does this accomplish what you're hoping to do?

P.S.: You may want to use a custom error message with this implementation, as the default error message will tell the user that their responses must total to 999.
answered Mar 4, 2016 by Zachary Platinum Sawtooth Software, Inc. (90,900 points)
Works Well...hv done something similar thing to make it working. Good to see another new brain in Sawtooth
Great solution and very simple.  I just ran into a similar problem with a grid setup where I was using Constant Sum and I wound up just changing it to Numeric showing the Total and writing some custom javascript verification to handle checking the total, but your solution would have been much easier.
0 votes
Please place this code in footer. This may helps you.

<script type="text/javascript">
var selflag=false;
      $(".numeric_input").select(function(event){selflag=true;});
      $(".numeric_input").bind("mousedown","blur",function(event){selflag=false;});
    $(".numeric_input").keydown(function(event) {
      
            //assign maximum value to be allowed to x i.e 100 or 999 or etc as per requirement
            var x=10000; // here you can place [% Q1 %] as per your requirement
            
        // Allow: backspace, delete, tab, escape, enter (. key code==190,110 required for decimal input, so append 190,110 in array for decimal input)}
            // Allow: Ctrl+A
            // Allow: home, end, left, right
        if ( $.inArray(event.keyCode,[46,8,9,27,13]) !== -1 || (event.keyCode == 65 && event.ctrlKey === true) || (event.keyCode >= 35 && event.keyCode <= 39))
            {
                  // let it happen, don't do anything
                  selflag=false;
                  return;
        }
            else
            {
                  // to allow range 0-x dynamically
                  var q,r,kc;
                  q=parseInt(x/10);
                  r=""+(x%10);
                  kc=r.charCodeAt(0);
            
                  if(($(this).val()>q || ($(this).val()==q && (event.keyCode < 48 || (event.keyCode > kc && event.keyCode <96) || event.keyCode > 96+(kc-48)))||($(this).val()!="" && $(this).val()==0 &&(event.keyCode == 48 || event.keyCode ==96))) && !selflag)
                  {
                        event.preventDefault();
                  }
                  //if something is selected in textbox allow only numbers 0-9 when x is greater than 9
                  if((selflag && ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))) && x>9)
                  {
                        selflag=false;
                        return ;
                  }
                  else if((selflag && ((event.keyCode >= 48 && event.keyCode <= kc) || (event.keyCode >= 96 && event.keyCode <= 96+(kc-48)))) && x<=9)
                  {
                        selflag=false;    //allows only upto 0-x if x<9
                        return ;
                  }
                  else if(selflag)
                  {
                        event.preventDefault();
                  }
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 ))
                  {
                event.preventDefault();
            }   
        }
    });
</script>
answered Mar 10, 2016 by Saritha potu
...