Forums

CF6 How to clear specific fields via reset button

xoles 20 May, 2017
Hi, in my form I use the events tab to add up values from several textfields into a "total sum" textfield. First save works just fine, but when trying to update that same form, if you change values from the fields it won't subtract and any other value you enter will sum to the previously loaded "total sum" value.

I thought that a reset button just for those fields (not for the entire form) would be a good solution, instead of coding a way to add or subtract depending on the new field value; but I can't figure out how to.

The reset-type button by itself won't clear any field, I think I'm missing a function or event. I created a button-type button and tried to javascript it to clear fields, but can't make it work. I don't know if the function js code goes before or after the button, or if I have to place something extra on the setup tab, or if it can be done with php.

Any suggestions on how to achieve this?
Max_admin 20 May, 2017
Hi xoles,

The reset button resets the fields to their default values when the form was loaded, so if your fields had some values already then the reset button can't clear them, instead you can clear them with JS:

$("#field_id").val("");


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
xoles 20 May, 2017
Thanks Max, I'm trying with no luck this js code before the input field:

 document.getElementById('reset').onclick= function() {
        $("#field_id").val("");
    };


and a button with id 'reset' after the input field. All these on design tab; nothing extra on setup tab.
GreyHead 21 May, 2017
Answer
Hi xoles,

The JS code should be in a Load JavaScript action on the Setup tab - not in the Design tab.

Bob
This topic is locked and no more replies can be posted.