Is there a way to submit different input data through a shared pre-generated HTML form template that uses unique variable names as titles? I have two buttons on my page with similar popover effects. When I click the submit
button inside a .popover-content
, both forms get submitted, even though one of them is hidden.
function handlePopover (button) {
const id = button.attr('id');
$(document).on('click', '#close', function(){
botton.popover('hide');
}
$(document).on('click', '#submit', function(){
if(id === 'button1') alert("button1");
else if(id === 'button2') alert("button2");
}
}
This is how I implemented the function:
const button1 = $("#button1");
const button2 = $("#button2");
handlePopover(button1);
handlePopover(button2);
I suspect the issue may be due to adding a listener like this: $(document).on(...)
. However, I am unsure how to resolve this problem. Is there a way to deactivate the listener when the popover content is hidden? Thank you for your assistance!