Lightbox on form submit

后端 未结 2 1187
刺人心
刺人心 2021-01-27 13:41

I am working on an ecommerce site for which, i want the add to cart button to open a lightbox with a form to accept some more details like quantity, etc. The problem is, the way

2条回答
  •  旧时难觅i
    2021-01-27 14:25

    Just attach a click handler onto the button that submits the form, like so:

    $("#id_of_submit_button").click(function(e) {
    
        e.preventDefault();
        e.stopPropagation();
    
    });
    

    That will keep the form from being submitted (or at least, it should). As for opening the lightbox, you should be able to just include that after the e.stopPropagation(); call above...just open it as normal.

    The major problem you are probably going to have is how to include the information from the additional form in the lightbox with the original form. You may just want to submit all of it via a $.post call, or perhaps do some $("form").append() calls to insert hidden fields into the original form based on the information in the lightbox?

提交回复
热议问题