javascript - Unable to get alert message while submitting form through jquery -


i trying submit form using jquery when click on submit button shows blank page , know blank page means form has been submitted that's not behavior want , want show alert() testing purpose showing blank page

html :

 <c:foreach items="${cartlist}" var="product"> <form id="editcart" method="post" action="">     <input type="text" id="pid" name="pid" value="${product.pid}" hidden/>     <input type="text" id="spid" name="spid" value="${product.sub_pid}" hidden/>     <input type="text" id="cartid" name="cartid" value="${product.cart_id}" hidden/>     <input type="text" id="quantity" name="quantity" value="${product.quantity}" disabled/>     <input type="button" value="edit" class="enable" />     <input type="submit" value="save" class="save" hidden/> </form> </c:foreach> 

and respective js :

$(function () {     $('.enable').click(function () {         $(this).prev('#quantity').prop('disabled', false);         $(this).hide();         $(this).next('.save').fadein();     }); });  $('#editcart').submit(function () {     alert();     return false;  }); 

now jquery enable hide working , have tested multiple times , form not submitting

as you've said form submitted , blank page shown, means submit event handler not working(i.e. return false in handler).

because haven't wrapped submit event handler in ready, event not bound. move submit handler in ready , should work.

$(function () {     $('.enable').click(function () {         $(this).prev('#quantity').prop('disabled', false);         $(this).hide();         $(this).next('.save').fadein();     });      $('#editcart').submit(function () {         alert();         return false;     }); }); 

also, .enable event handler can refactor follow:

$('.enable').click(function () {     $('#quantity').prop('disabled', false); // id unique, no need use prev()     $(this).hide().next('.save').fadein(); // chained }); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -