• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Populate a dropdown based on a score

Populate a dropdown based on a score 10 years 5 months ago #29366

  • ongobay
  • ongobay's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi,

I am wanting to use the form for a risk assessment.

The logic is that people will select certain things and a total is compiled on the back of it.

I have the calculations fine, so if people select certain answers then a score is attached to it. At the end I have a total.

I then want to populate a dropdown based on the total.

So for example if the total was between 0 - 5, the dropdown would prepopulate with "Not at risk", if the score was between 6 - 10 it would prepopulate "mild risk". 11 - 15 Moderate risk, and so on.

I'm doing it this way as I want to email out a small report using the data from the dropdowns.

Does anyone have nay suggestions?

I would really appreciate it.

Thanks,
Chris
The administrator has disabled public write access.

Populate a dropdown based on a score 10 years 5 months ago #29382

  • ongobay
  • ongobay's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
For anyone interested I did this with some php.

I mostly just changed information that was already available on the forum. "risk_factor" is a hidden field.


// Define the score range
$firstrange = range(0, 5);
$secondrange = range(6, 10);
$thirdrange = range(11, 15);
$forthrange = range(16, 99);

// The code

if(in_array($_POST, $firstrange)){
$_POST = '<strong> Not at Risk </strong>';}
else if (in_array($_POST, $secondrange)){
$_POST = 'Mild Risk';}
else if (in_array($_POST, $thirdrange)){
$_POST = 'Moderate Risk';}
else if (in_array($_POST, $forthrange)){
$_POST = 'SIGNIFICANT RISK';}
The administrator has disabled public write access.

Populate a dropdown based on a score 10 years 5 months ago #29383

  • ongobay
  • ongobay's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
I also have a large drop down list which the user selects which contains various regions.

I want to use their selection to populate a hidden field which will contain text which will go in an email. So if the user selects "new york" for example, it would put some text I have already specified. So the email might say

"You've selected New York. We suggest you visit The Statue of Liberty." In real terms this would be something like "You've selected {City}, we suggest you visit {tourist place}".

Whats the best way to do this? I could do it similar to the php code above, however the dropdown list I have contains 400 pieces of data, so the php code would be huge and probably crude. Any suggestions?
The administrator has disabled public write access.

Populate a dropdown based on a score 10 years 5 months ago #29387

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Dropdown items are composed out of two elements: value and label. Syntax: value|label. More details on this here:

http://www.rsjoomla.com/support/documentation/view-article/827-dropdown.html

In your case, you could use something like this:

Email message here|New York

Within the email body configuration you would use the value placeholder for the dropdown.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Populate a dropdown based on a score 10 years 5 months ago #29390

  • ongobay
  • ongobay's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
Hi Alex,

Thanks for that. I thought this was perfect for what I needed, but it will restrict me to only 1 item. Do you suggest a way for one dropdown to copy another?

Also, the "email message here" bit might be quite long and when I've done a large list, the "email message here" and "new york" value | label are not correct. It is hard to explain, but the value and label are not the ones together. For example if I select number 8 on the list, it is displaying the "New york" correctly, but the email text is from number 4 on the list instead.

Any ideas?

Thanks,
Chris
The administrator has disabled public write access.

Populate a dropdown based on a score 4 years 11 months ago #40168

  • manuel.berger
  • manuel.berger's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
  • Thank you received: 1
Even this is what a 5 year old post, I try to solve something similar.
Does anyone has an idea where to put this php code to have a result based on a range?
ongobay wrote:
For anyone interested I did this with some php.

I mostly just changed information that was already available on the forum. "risk_factor" is a hidden field.


// Define the score range
$firstrange = range(0, 5);
$secondrange = range(6, 10);
$thirdrange = range(11, 15);
$forthrange = range(16, 99);

// The code

if(in_array($_POST, $firstrange)){
$_POST = '<strong> Not at Risk </strong>';}
else if (in_array($_POST, $secondrange)){
$_POST = 'Mild Risk';}
else if (in_array($_POST, $thirdrange)){
$_POST = 'Moderate Risk';}
else if (in_array($_POST, $forthrange)){
$_POST = 'SIGNIFICANT RISK';}
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!