Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I figured out how to create a reset button in Javascript and it is resetting the fields in the form that are field type drop-down, text and date. But it is not working on resetting the fields that are multi-select and checkbox group. I’m doing it inside Confluence within ConfiForms.

I basically just need a Javascript solution that works for resetting or clearing fields for multi-select or checkbox group.



function my CustomScript(formId) {

AJS.$('#' + fomdId).find('.save-cf-btn').after('<button type="button"` class="aui-button cf_reset_btn" style="margin=right: 10px;">Reset</button>');
AJS.$('#' + formID).find('.cf_reset_btn').click(function() {
AJS.$('#' + formID).find('#i_totr').val('');
AJS.$('#' + formID).find('#i_title').val('');
});
}



What I have tried:

I tried the below but that didnt work.

function cfSetValue(formId, 'my multiselect field', '',
true);


});
Posted
Updated 20-Oct-22 6:43am
Comments
Chris Copeland 19-Oct-22 4:13am    
Just out of curiosity, why aren't you using <button type="reset"> ?
Member 15802160 20-Oct-22 12:12pm    
That's just the way I’ve been creating buttons with JavaScript.

1 solution

I'd recommend using the <button type="reset"> button to clear forms down. It requires no Javascript and is handled by the browser.

If you're set on using Javascript then you need to use the appropriate prop() method to change the states of the input elements:

JavaScript
// For checkboxes
$('#checkbox').prop('checked', false);

// For select options
$('#select option').prop('selected', false);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900