How to set a field depending on select-from-list-field value before Submit

  • OPape
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 0

OPape created the topic: How to set a field depending on select-from-list-field value before Submit

Hi,

how it is possible to set a (hidden) field depending of the value of a select-from-list field after user press 'Submit'?

I tried it with a submit pieces with switch statement. I also tried it with easy if-then-else-structure. None works.

Does anyone have a sample code snippet for me?

Thanks a lot.
#237572
  • Posts: 2553
  • Karma: 87
  • Thank you received: 343

mihaela replied the topic: How to set a field depending on select-from-list-field value before Submit

Hello,

I see two ways to set the hidden field value:

1) Would it be acceptable for you to set the value of the hidden field after a change is made in select list?
If yes, do as follows:
Go to the Advanced properties of the select list element and in the Actionscript section set Type to Custom and Action to Chance. In the code area below put the following code:
function ff_selectListName_action(element, action)
{
if(element.value == "option1") {
    ff_getElementByName("hiddenElementName").value="value1";
    }
else if(element.value == "option2") {
    ff_getElementByName("hiddenElementName").value="value2";
    }
else if(element.value == "option3") {
    ff_getElementByName("hiddenElementName").value="value3";
    }

} // ff_selectListName_action
NOTE: In the code above you have to replace every instance of selectListName with the actual name of the select list element. Also, replace every instance of hiddenElementName with the name of the hidden element.
Finally, adjust the options and values to suit your case.

2) To change the value of hidden filed after user presses "Submit" you need to create a custom submit button.
Follow these instructions:
a) Go to your form's Properties and set Include submit button to No. That will remove regular submit buttons.

b) On page 2 create new element of Submit button type. What you write in the Value field for that button element is what will be displayed on that button in your form, so that it the place where you should put, for example, "SUBMIT" since this button will use to submit the form. Give this element name "submit".

6) Go to Advanced properties of that next button element and in Actionscript section set Type to Custom and mark Click as Action.
In the code area below put the following code:
function ff_submit_action(element, action)
{
if( ff_getElementByName("selectListName").value == "option1") {
    ff_getElementByName("hiddenElementName").value="value1";
    }
else if( ff_getElementByName("selectListName").value == "option2") {
    ff_getElementByName("hiddenElementName").value="value2";
    }
else if( ff_getElementByName("selectListName").value == "option3") {
    ff_getElementByName("hiddenElementName").value="value3";
    }
if(typeof bfUseErrorAlerts != 'undefined'){
     JQuery(".bfErrorMessage").html('');
     JQuery(".bfErrorMessage").css("display","none");
    }
    error = ff_validation(0);
    if (error != '') {

        if(typeof bfUseErrorAlerts == 'undefined'){
           swal(error);
        } else {
           bfShowErrors(error);
        }
        ff_validationFocus();
    } else
        ff_submitForm();
      }
    });
           
} // ff_submit_action
NOTE: In the code above you have to replace every instance of selectListName with the actual name of the select list element. Also, replace every instance of hiddenElementName with the name of the hidden element.
Finally, adjust the options and values to suit your case.

Let me know whether you have managed to set this for your form.

Regards,

Mihaela
#237581
Moderators: ForumSupporttomeperica
Time to create page: 0.056 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