Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript code is deleting row on hit enter and button click

Javascript code is deleting row on hit enter and button click
Below code is working deleting row on button click but even if i am entering text in input field and if i press ENTER it is deleting the row also. I am using this for multiple fields generated dynamically.

How can i avoid the deletion of row on pressing enter?

Javascript

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//===== delete the form field row
$("body").on("click", ".remove_node_btn_frm_field", function () {
   $(this).closest(".form_field_outer_row").remove();
});

>Solution :

A HTML button element’s default type is submit, a side effect of this is that is also captures the enter key.

If this button is not meant to submit a form, you will want to make sure the type is set to button.

<button type="button">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading