JSP/HTML required fields only for specific submit button

I have table for user with 8 fields to complete fields via input type="text". I have added to 4 fields tag "required". And 4 buttons input type="submit":

add
delete
edit
deactivate

The problem is that "required" field is checked for all submit buttons, but I want it to be checked only when "add" button is pushed. Is there any way to bind "required" field to specific button?

Answers


Try it please.

$("form input[type=submit]").click(function() {
   //console.log($(this).val());
   if($(this).val()!=="ADD"){
      $('form input[type=text]').each(function() {
         $(this).removeAttr("required");
      });
   }
   $("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
   $(this).attr("clicked", "true");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action='nothing' method='post' name='testform'>
    <input type="text" id="name" required>
    <input type="text" id="age" required>
    <input type='submit' name='add' value='ADD' />
    <input type='submit' name='delete' value='DELETE' />
</form>

Need Your Help

Triangle count for model is doubled during render

shader triangle-count

I am working with the Trinigy 3d engine, and it reports models to have twice as many triangles during render than it does in the model display (let's say 4000 instead of 2000). If I render the mode...