CRAIG
CRAIG

Reputation: 1029

Remove a Hidden Form Element from a Specific/Selected Form

I am adding form elements within a modal to a form in the parent page. That form's ID is file_form.

However, when the person UN checks the checkbox, I also need to remove any current hidden inputs tied to the file_form form. I have seen how to generally remove hidden form elements using .remove, but not how to specifically remove them from a specific form? Here is what I tried:

if($(this).is(':checked')) {
     var thecat = $(this).val();

$('#file_form').append('<input type="hidden" name="caty[]" value='+ thecat + ' />');
} else {

 $('#file_form').append($('input[type="hidden"][value="'+thecat+'"]').remove());

}

Upvotes: 1

Views: 879

Answers (1)

Use Attribute Equals Selector [name="value"]

$('#file_form input[type="hidden"]').remove();

$('#file_form input[type="hidden"]') find all the type="hidden input elements in the element with id file_form

Upvotes: 2

Related Questions