Reset form values on turn off

  • Posts: 3128
  • Karma: 105
  • Thank you received: 413

mihaela replied the topic: Reset form values on turn off

Hello,

I understand want to achieve.

Here is the code that will clear fields when select list is changed to any value, in this case any of values from value1 to value6.
function ff_selectlist_action(element, action)
{
    switch (action) {
        case 'change':
           ff_getElementByName('textfield1').value = '';
           ff_getElementByName('textfield2').value = '';
           ff_getElementByName('textfield3').value = '';
           ff_getElementByName('textfield4').value = '';
            break;
        default:;
    } // switch
} // ff_selectlist_action
The simplest way is to just omit the if statement. This script will be run each time the selected option in select list element is changed.

Let me know whether this works as wanted.

I thought that you have a possibly lengthy form and that you want that all form fields are cleared after the selected option in select list element is changed.

In that case the following code would do the trick:
function ff_selectlist_action(element, action)
{
    switch (action) {
        case 'change':
            var tmp = ff_getElementByName('selectlist').value;
            eval('document.'+ff_processor.form_id).reset();
            ff_getElementByName('selectlist').value = tmp;
            break;
        default:;
    } // switch
} // ff_selectlist_action
The following line of code would reset all form fields
eval('document.'+ff_processor.form_id).reset();
so it wouldn't be needed to reset each field individually like this:
ff_getElementByName('textfield1').value = '';
ff_getElementByName('textfield2').value = '';
ff_getElementByName('textfield3').value = '';
ff_getElementByName('textfield4').value = '';

I hope that you understand what I'm trying to explain.
I think in your case it is the simplest to use first solution.

Regards,

Mihaela
#231932
  • Posts: 16
  • Thank you received: 0

LaurieM replied the topic: Reset form values on turn off

Hi there!

Thanks for the help.

Using the first option in the previous post, with one level of conditional fields, I can clear the fields upon change of mind by the visitor.

However, I can't work out how the the js should go when I have nested conditional fields.

I have:

A select list with a name Division. It has 8 options (Programs).

Each Program has a conditional select list with 2 to 10 options, one of which in each case is Other.

If Other is selected in any of the second level select lists, then a conditional textfield, belonging to that program, opens.

The possible "change of mind" options are to change from Other to one of the listed programs or to change from one Division to another.

This is where I need to clear the Other fields.

Note: I'm js illiterate but have got my head around what's happening to some extent.

My problem seems to be working out what js code to put in the Action Script of which element and what values to include.

I'm hoping you can help me with either the way I've been trying to accomplish this or another way to get the same result, maybe using a Radiogroup for the second level.

Thanks,
Laurie.
#238164
Moderators: ForumSupport
Time to create page: 0.046 seconds

We Are Doing Our Part

Massive discounts on all of our extension subscription plans to help you and your business in these times.

Get Your Subscription Here

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!

News and Updates

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

All Extensions Subscription

We are doing our part and support your business with extremely low prices -- For example 6-Months-Subscription for only $9 USD. For as long as necessary.

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!