Urgent help needed creating javascript permutation and combination function

I really need urgent help in creating a permutation and combination function in my form. In this form users will input a 4 digit number (tablename___numbers) and there is a checkbox named “Box” (tablename___box) when user click on the checkbox it will count the total number of permutation and combination of the input numbers (tablename___numbers). for exmaple 0001 (3 same digit) = 4, 1100 (2 same digit = 6) and so on…

Form Id 25
I have tried a few coding but fail to get it running Please help to see where I have gone wrong. Thanks in advance.

var tablename___box = tablename___numbers[0];
form_25.tablename___box.get(‘tablename___numbers’).getValue();
function disableBox(thisid)
{
var tablename___box = jQuery.trim($(“form_25.tablename___numbers” + thisid).val());
if(no.length != 4){

$('tablename___box ’ + thisid).attr(“disabled”, true);

$('tablename___box ’ + thisid).prop(‘checked’, false);
}
else {
var combinationCount = checkDigit(no);
$('tablename___box ’ + thisid).val(combinationCount);
$('tablename___box ’ + thisid).attr(“disabled”, false);
}
}
function checkDigit(val)
{
var b = form_25.tablename___box .get(‘tablename___numbers’).getValue();
var same = 0;
var kcount = 0;
var returnData = 1;
for(var i=0; i<4; i++){
kcount++;
for(var j=kcount; j<4; j++){
if(val.charAt(i) == val.charAt(j)){
same++;
}
}
}
if(same == 4){
returnData = 1;
}else if(same == 3){
returnData = 4;
}else if(same == 2){
returnData = 6;
}else if(same == 1){
returnData = 12;
}else{
returnData = 24;
}

return returnData;
}

I would recommend you google for how to calculate permutations and combinations.

I already have the formula but I need to know how to code it in Javascript.
when user enter any 4 digit number example 0001 in the number field and click on the checkout name “Box” the form will return value 4

var tablename___box = tablename___betted_numbers[0];
form_25.tablename______box.get(‘tablename______betted_numbers’).getValue();
function disableBox(thisid)
{
var tablename______box = jQuery.trim($(“form_25.tablename___betted_numbers” + thisid).val());
if(no.length != 4){

$(‘tablename___box’ + thisid).attr(“disabled”, true);

$(‘tablename___box’ + thisid).prop(‘checked’, false);
}
else {
var combinationCount = checkDigit(no);
$(‘tablename___box’ + thisid).val(combinationCount);
$(‘tablename___box’ + thisid).attr(“disabled”, false);
}
}
function checkDigit(val)
{
var b = form_25.tablename___betted_numbers.get(‘tablename___betted_numbers’).getValue();
var same = 0;
var kcount = 0;
var returnData = 1;
for(var i=0; i<4; i++){
kcount++;
for(var j=kcount; j<4; j++){
if(val.charAt(i) == val.charAt(j)){
same++;
}
}
}
if(same == 4){
returnData = 1;
}else if(same == 3){
returnData = 4;
}else if(same == 2){
returnData = 6;
}else if(same == 1){
returnData = 12;
}else{
returnData = 24;
}

return returnData;
}

This code is what I have tried but its not generating result. my form id is 25 with element number and Box. When user enter 0001 in the number field and click the checkbox the form will return 4 I need help to see where I gone wrong

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.