0

I have a bootstrap modal where the users fill out a form and upon clicking submit, it opens the user's mail client using a mailto link and populates a new message.

I would like the modal to close when this happens, but when I add code to close the modal, the mailto link no longer works (mail client window does not open). The modal successfully closes. Any suggestions?

 $('#request-form').submit(function (evt) {               
            if ($("#request-form").valid())
            {
                evt.preventDefault();

                var firstName = $("#FirstName").val();
                var lastName = $("#LastName").val();
                var company = $("#Firm").val();
                var address = $("#Address").val();
                var city = $("#City").val();
                var state = $("#State").val();
                var zip = $("#Zip").val();
                var phone = $("#Phone").val();
                var email = $("#EmailAddress").val();
                var product = $("#ProductName").val();

                //Send email using mailto link
                var body = "Send this email <removed>.%0D%0A%0D%0AFirst Name: " + firstName + "%0D%0ALast Name: " + lastName + "%0D%0ACompany: " + company +
                    "%0D%0AAddress: " + address + "%0D%0ACity: " + city + "%0D%0AState: " + state + "%0D%0AZip: " + zip + "%0D%0APhone: " + phone + "%0D%0AEmail: " + email +
                    "%0D%0AProduct: " + product;

                var subject = "Product Request";
                var recipient = $("#Recipient").val();

                window.location.href = "mailto:" + recipient + "?subject=" + subject + "&body=" + body;                    
                $("#questions-modal").modal('hide');


            }               
        });

cshtml:

<button type="submit" class="btn btn-nav pull-right" id="btn-openMail" data-dismiss="modal">Submit</button>
4
  • 2
    Works in a fiddle
    – mccannf
    Oct 2, 2014 at 18:38
  • This code fragment seems incomplete. Please include your full JS.
    – cvrebert
    Oct 2, 2014 at 20:53
  • Updated my snippet to include the whole function. The fiddle worked, interesting... can't see how to relate what you did there to make changes on my end, though.
    – Kelly
    Oct 3, 2014 at 18:32
  • OMG it was the wrong modal id in the selector. That was it! It's supposed to be "#request-modal" not "#questions-modal"!! Whoops. It works now with using modal('hide'). I did not need the data-dismiss="modal" by the way.
    – Kelly
    Oct 3, 2014 at 18:38

1 Answer 1

0

You could try with "toggle"...

$("#questions-modal").modal('toggle');

or put some extra code.

Did you check console logs?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.