CONDITIONAL FIELDS

  • DAVIDPL
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0

DAVIDPL created the topic: CONDITIONAL FIELDS

I WOULD LIKE TO AUTOMATICALLY ASSIGN A VALUE TO A FIELD DEPENDING ON THE VALUE CHOSEN IN A DISPLAYABLE LIST


I need to perform the following action:

There is a type field (drop-down list) called: "2_sport" with several values ​​(Judo, Aikido, Kendo, Wu Shu, Jiu Jitsu, Defense),
I want that when you select any of the values ​​in the list, export to another field called "Amount2D" the value: "Price" assigned
according to the variables introduced.

Campos lista desplegable
0;Seleccionar;
0;Judo;1
0;Aikido;2
0;Kendo;3
0;Jiu Jitsu;4
0;Wu shu;5
0;Defensa;6


Variables asignadas al campo (2_deporte)
Valor 1 = 51 euros
Valor 2 = 52 euros
Valor 3 = 53 euros
Valor 4 = 54 euros
Valor 5 = 55 euros
Valor 6 = 56 euros

MI CODIGO
function ff_Homologacion_de_club_init()
{ setInterval(calc, 500);
} //ff_Homologacion_de_club_init

function calc(preciototal) {
var vdeporte2d = (ff_getElementByName('2_deporte').value);

if (vdeporte2d = "Judo") {
ff_getElementByName('Importe2D').value= "51"; }

else if (vdeporte2d = "Aikido") {
ff_getElementByName('Importe2D').value= "52"; }

else if (vdeporte2d = "Kendo") {
ff_getElementByName('Importe2D').value= "53"; }

else if (vdeporte2d = "Jiu Jitsu") {
ff_getElementByName('Importe2D').value= "54"; }

else if (vdeporte2d = "Wu Shu") {
ff_getElementByName('Importe2D').value= "55"; }

else if (vdeporte2d = "Defensa") {
ff_getElementByName('Importe2D').value= "56"; }


} // ff_Homologacion_de_club_init
#238726
  • Posts: 2986
  • Karma: 104
  • Thank you received: 394

mihaela replied the topic: CONDITIONAL FIELDS

Hello,

What I see at the first glance is that the if statement will never be fulfilled because what gets saved as
ff_getElementByName('2_deporte').value
is not "Judo", "Aikido" etc., but the numbers 1,2,.., because you have defined list like this:
0;Seleccionar;
0;Judo;1
0;Aikido;2
0;Kendo;3
0;Jiu Jitsu;4
0;Wu shu;5
0;Defensa;6

What gets saved as value is what you put after the second semicolon in each line.

Therefore, the code should go something like:
function ff_Homologacion_de_club_init()
{ setInterval(calc, 500);
} //ff_Homologacion_de_club_init

function calc() {
var vdeporte2d = (ff_getElementByName('2_deporte').value);

if (vdeporte2d = "1") {
ff_getElementByName('Importe2D').value= "51"; }

else if (vdeporte2d = "2") {
ff_getElementByName('Importe2D').value= "52"; }

else if (vdeporte2d = "3") {
ff_getElementByName('Importe2D').value= "53"; }

else if (vdeporte2d = "4") {
ff_getElementByName('Importe2D').value= "54"; }

else if (vdeporte2d = "5") {
ff_getElementByName('Importe2D').value= "55"; }

else if (vdeporte2d = "6") {
ff_getElementByName('Importe2D').value= "56"; }


} // ff_Homologacion_de_club_init

Let me know whether this is working as you wanted.

Regards,

Mihaela
#238728
  • DAVIDPL
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0

DAVIDPL replied the topic: CONDITIONAL FIELDS

HELLO Mihaela,

Unfortunately it does not work, the following occurs: it always indicates the same response value on 51, selecting any option, the code interprets that the first option 1 is correct
#238760
  • Posts: 2986
  • Karma: 104
  • Thank you received: 394

mihaela replied the topic: CONDITIONAL FIELDS

Hello,

I see now another mistake in the code. I probably didn't notice it since I've found the other error so I thpught that was the issue. In the "if" statements when defining the equality check you must always use "==" instead of "=".

Therefore, the code should look like this:
function ff_Homologacion_de_club_init()
{ setInterval(calc, 500);
} //ff_Homologacion_de_club_init

function calc() {
var vdeporte2d = (ff_getElementByName('2_deporte').value);

if (vdeporte2d == "1") {
ff_getElementByName('Importe2D').value= "51"; }

else if (vdeporte2d == "2") {
ff_getElementByName('Importe2D').value= "52"; }

else if (vdeporte2d == "3") {
ff_getElementByName('Importe2D').value= "53"; }

else if (vdeporte2d == "4") {
ff_getElementByName('Importe2D').value= "54"; }

else if (vdeporte2d == "5") {
ff_getElementByName('Importe2D').value= "55"; }

else if (vdeporte2d == "6") {
ff_getElementByName('Importe2D').value= "56"; }


} // ff_Homologacion_de_club_init

Let me know whether this is working as you wanted.

Regards,

Mihaela
#238771
  • DAVIDPL
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0

DAVIDPL replied the topic: CONDITIONAL FIELDS

Hi
It went well, perfect

I have another question that I want to solve and it is the following:

I have a code to add three fields: ('Importe1D')+('Importe2D').....and accumulate it to a total ('Total'), I have it done with a (Actionscript)
I would like to automate it so that when the values ​​change automatically it recalculates them, I think it should be done in an (Initialization Script) I would like to adapt the code that I have in actionscript to do it in initialization script

MI CODIGO (actionscript):
function ff_Total_action(element, action)
{
switch (action) {
case 'select':

ff_getElementByName('Total').value = 0;
ff_getElementByName('Total').value = (Number(ff_getElementByName('Importe1D').value) + Number(ff_getElementByName('Importe2D').value) + Number(ff_getElementByName('Importe3D').value) + Number(ff_getElementByName('Importe4D').value) + Number(ff_getElementByName('Importe5D').value));

break;
default:;
} // switch
} // ff_Total_action
#238780
  • Posts: 2986
  • Karma: 104
  • Thank you received: 394

mihaela replied the topic: CONDITIONAL FIELDS

Hello,

The code that you have written should perform a change in the total field each time that you make a change in one of the fields included in the calculation (assuming that you have written the Actionscript code for each of the fields as it should be done crosstec.org/en/support/online-documenta...ting-textfields.html ).

The only thing that this change in total will be conducted when you click anywhere on the form despite the field you are currently changing.

If you wish to write the code in the Initialization script so that the code is run every half second let's say, here is what you would need to do.

In the Advanced properties of the "total" filed go to the "Initscript" section. Set Type to Custom and check the "Page Entry" checkbox.

In the code area that appears put the following code:
function ff_Total_init(element, condition)
{ setInterval(calc, 500);
} //ff_Total_init

function calc() {
ff_getElementByName('Total').value = (Number(ff_getElementByName('Importe1D').value) + Number(ff_getElementByName('Importe2D').value) + Number(ff_getElementByName('Importe3D').value) + Number(ff_getElementByName('Importe4D').value) + Number(ff_getElementByName('Importe5D').value));
} 

Let me know whether this is working as you wanted.

Regards,

Mihaela
#238794
Moderators: ForumSupporttomeperica
Time to create page: 0.085 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here