I am currently working on a Squarespace form that utilizes jQuery to show/hide specific fields in order to create a customized form using the show(); and hide(); functions.
$(".option2 select").hide();
The issue I am facing is that simply hiding the fields does not remove them from the DOM, resulting in hidden fields still being submitted in the Squarespace email.
$(".option2 select").remove();
Although using remove(); successfully eliminates the select field from the DOM and prevents it from being included in the form submission, this action is irreversible and breaks the entire form.
Is there a way to execute remove(); on certain elements right before the submit button is pressed to permanently erase them from the DOM prior to actual form submission?
Edit: To clarify, since this project is based on Squarespace, utilizing onSubmit proves challenging due to existing components. Therefore, I am seeking a jQuery-exclusive solution that does not involve modifying any of the HTML directly.