Required wont work
I'm trying to make each of the expense amount fields required before calculating the total but the required attribute in each element isn't working. anyone know what I'm doing wrong? I tried putting the total_expense button inside the form but when that happens the whole page resets or just wiggs out when to click it. <!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body> <input type="button" value="Add Expense" onclick="add_expense()"><br> <form> <div id="box"> </div> </form> <input type="submit" value="Total Expenses" onclick="calc_expense()"> <br> <input type="text" id="net_exp"/> </body> </html> var x = -1; var all_exp = 0; function add_expense(){ x += 1; $('#box').prepend("<div class='expense'><input type='text' placeholder='Expense Name'/><input type='text' placeholder='Amount' class='e' required='required'/><input type='button' class='remover' value='Remove' onclick='remove_expense()'/><br><br><br></div>"); } function calc_expense(){ all_exp=0; $('.e').each(function(){ all_exp += parseInt($(this).val()); }); $('#net_exp').val(all_exp); } function remove_expense(){ $('.expense')[0].remove(); }