Show field type "check box" values sum

Ask your questions here.
Post Reply
ahmedvolks
Posts: 88
Joined: 09 May 2017, 11:10
Name: Ahmed Reda
Location: Egypt
Company Name: kalaweeza.com
Contact:

Show field type "check box" values sum

Post by ahmedvolks »

Hello,
I need to show immediate score for a technical test. using the check box as shown below.
technical-test.png
This is a recruitment form for new candidates in an interview.
I need each checked question value to be added to the score.
Like the value is 7.14 for each questions, and if he answered three questions the score will be 21.42.
Whatever the numbers I need to make SUM for the value of the correct questions.

I tried the function but it show the ID like 1024,1025,1026 when count and show 1024 in SUM.
Each line (record) is a new comer test So I need the calculations be done for each line (record) and not for the table list.

Thank you
Didou12
Posts: 487
Joined: 14 Jan 2023, 14:53
Name: Louis
Location: Montreal, Canada

Re: Show field type "check box" values sum

Post by Didou12 »

Hi,

Sure, you can make this with ajax field and put this code :

Code: Select all

$list = [123]; //id of the checkbox field
$total_query = db_query("select SUM(value) as total from app_fields_choices where id in ($list)",false); //use "app_fields_choices" if list of choices is directly in the checkbox field without a global list, and "app_global_lists_choices" if list of choices is a global list
$value = 0; //total value by default
if($total = db_fetch_array($total_query))
{
  $value = $total['total'] ?? $value;
  echo $value; //output value, or delete this line if you don't want to display it in the form
  $form_field_value = $value; //value to save in database, or delete this line if you don't want to save it in the database
}

Also, do you need JS verification to block the submission if the total is not ok ?
Using Rukovoditel since 2022 --- v3.4 (with extension) in French on PHP 8.2
I keep the French translation up to date
I'm trying to help you (+10 years experience in html, css, php, sql, JS/jquery, python)
ahmedvolks
Posts: 88
Joined: 09 May 2017, 11:10
Name: Ahmed Reda
Location: Egypt
Company Name: kalaweeza.com
Contact:

Re: Show field type "check box" values sum

Post by ahmedvolks »

Thank you for your help :)
I have made as shown in the images below.
2024-01-01_15-22-49.png
Recruitment fields1.png
Recruitment fields Answered1.png
Recruitment fields Answered1.png (17.02 KiB) Viewed 196 times
Recruitment fields Acrore3.png
- I need in the Answered field number "4".
- Each Technical Question have a value and I checked "Display option values". It shows the fields ID as appear. The number of questions are 14 and each answer value is 7.14 so all count 100 of 100 so I need it to be viewed as like "21".
Do you see this is a good idea or you have better method for exam percentage.
Technical Questions Fields Choices.png
Didou12
Posts: 487
Joined: 14 Jan 2023, 14:53
Name: Louis
Location: Montreal, Canada

Re: Show field type "check box" values sum

Post by Didou12 »

For score : you need an Ajax field not a JS formula. I gave you a php code not a JS.

https://docs.rukovoditel.net/index.php?p=99



For the other question. I will answer you later in the day 🙂.
Using Rukovoditel since 2022 --- v3.4 (with extension) in French on PHP 8.2
I keep the French translation up to date
I'm trying to help you (+10 years experience in html, css, php, sql, JS/jquery, python)
Didou12
Posts: 487
Joined: 14 Jan 2023, 14:53
Name: Louis
Location: Montreal, Canada

Re: Show field type "check box" values sum

Post by Didou12 »

I didn't know but with JS formula is more simple (calculation is automatic) :

Code: Select all

get_value([123])
where 123 is the list of checkboxes field


For your total of checked (in a JS formula too) :

Code: Select all

countChecks(String([123]));
function countChecks(x)
{
  if (x === '') {
    return 0;
  }
  return x.split(',').length;
}
where 123 is the list of checkboxes field



You can also count the total of checked and in the other formula (score) do (and change the output number with 0 for decimals in options if you want) :

Code: Select all

[456]*7.14
where 456 is the field for the count
Using Rukovoditel since 2022 --- v3.4 (with extension) in French on PHP 8.2
I keep the French translation up to date
I'm trying to help you (+10 years experience in html, css, php, sql, JS/jquery, python)
ahmedvolks
Posts: 88
Joined: 09 May 2017, 11:10
Name: Ahmed Reda
Location: Egypt
Company Name: kalaweeza.com
Contact:

Re: Show field type "check box" values sum

Post by ahmedvolks »

Thank you for the care :)
I'm happy to show you the result.
Form in list view
1.png
And below each item field for reference for any friend need it later.

Answered:
get_value([1571])/7
2.png
Suffix of 14

Score:
$list = [1571]; //id of the checkbox field
$total_query = db_query("select SUM(value) as total from app_fields_choices where id in ($list)",false); //use "app_fields_choices" if list of choices is directly in the checkbox field without a global list, and "app_global_lists_choices" if list of choices is a global list
$value = 0; //total value by default
if($total = db_fetch_array($total_query))
{
$value = $total['total'] ?? $value;
echo $value; //output value, or delete this line if you don't want to display it in the form
$form_field_value = $value; //value to save in database, or delete this line if you don't want to save it in the database
}
3.png

Technical Suggestion (was Decision):
if([1573]>80,'Accepted','Rejected')
4.png
ahmedvolks
Posts: 88
Joined: 09 May 2017, 11:10
Name: Ahmed Reda
Location: Egypt
Company Name: kalaweeza.com
Contact:

Re: Show field type "check box" values sum

Post by ahmedvolks »

Thank you :)
Didou12
Posts: 487
Joined: 14 Jan 2023, 14:53
Name: Louis
Location: Montreal, Canada

Re: Show field type "check box" values sum

Post by Didou12 »

Good job !!! 👏 And good idea the « suffix » 😃
Using Rukovoditel since 2022 --- v3.4 (with extension) in French on PHP 8.2
I keep the French translation up to date
I'm trying to help you (+10 years experience in html, css, php, sql, JS/jquery, python)
Post Reply