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.

const tablename___box = tablename___numbers[0]
form_25.tablename___box.get('tablename___numbers').getValue()
function disableBox (thisid) {
const 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 {
const combinationCount = checkDigit(no)
$('tablename___box ' + thisid).val(combinationCount)
$('tablename___box ' + thisid).attr('disabled', false)
}
}
function checkDigit (val) {
const b = form_25.tablename___box.get('tablename___numbers').getValue()
let same = 0
let kcount = 0
let returnData = 1
for (let i = 0; i < 4; i++) {
kcount++
for (let 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
}

checkDigit is the formula for calculating number of permutation and combination for example user enter 0001 in the number field and click the checkbox (“Box” ) it will check the digit entered in the number field and respond 4 because 3 same digit = 4 and when user enter 0011 it will return 6 because 2 same digit = 6 etc…

For future reference, you can select your pasted code and click on the </> icon in the menu at the top of the text editor and it will format it as a code block when you submit your post.

I have done it for you this time.

Just to note, I had your code in my editor and standardJS picked up on a few things

function disableBox (thisid) {
// 'tablename___box' is assigned a value but never used
const tablename___box = jQuery.trim($('form_25.tablename___numbers' + thisid).val())
// 'no' is not defined.
// I don't know if this is a Global variable elsewhere in your code.
if (no.length !== 4) {
...

A bit further down

function checkDigit (val) {
// 'b' is assigned a value but never used.
const b = form_25.tablename___box.get('tablename___numbers').getValue()
...

At this point, i think the issue is the definition of no in the disableBox command, as rpg_digital hinted at. checkDigit, if supplied with appropriate input, works correctly.