最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Submit form from a modal bootstrap - Stack Overflow

programmeradmin7浏览0评论

I have a form that lunchs a modal for confirmation before submitting, this modal has the submit button and is not inside the <form>, is working everywhere besides IE, in IE it just doesnt do anything.

<form action="" id="form" name="form" > // start form

In the modal this is the submit button

<button id="btnSend" type="submit" form="form">OK</button> 

Tried to add a hidden submit button in the form as suggestted in other post but didnt work.

I have a form that lunchs a modal for confirmation before submitting, this modal has the submit button and is not inside the <form>, is working everywhere besides IE, in IE it just doesnt do anything.

<form action="" id="form" name="form" > // start form

In the modal this is the submit button

<button id="btnSend" type="submit" form="form">OK</button> 

Tried to add a hidden submit button in the form as suggestted in other post but didnt work.

Share Improve this question edited Apr 11, 2017 at 18:03 DontVoteMeDown 21.5k10 gold badges72 silver badges113 bronze badges asked Apr 11, 2017 at 18:00 Tyra PululiTyra Pululi 4461 gold badge8 silver badges19 bronze badges 1
  • You could try posting the form with js in case of IE: document.getElementById('form').submit(). Just trigger this code when user clicks the modal confirmation button. – DontVoteMeDown Commented Apr 11, 2017 at 18:04
Add a ment  | 

2 Answers 2

Reset to default 5

The form attribute does not supported by IE or Edge. So, you should handle click action and submit your form manually to support cross browser.

You also needs to add a hidden submit button in your form if you want end user submit form when press enter on input fields..

document.getElementById('btnSend')
    .addEventListner('click', function (event) {
        document.getElementById('form').submit();
    })
;

edit: Overview of Browsers supporting form-attribute caniuse

$(document).on('click', '#btnSend', function() {
	$('#form').submit();
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<form action="" id="form" name="form" onSubmit="alert('submitted')"></form>

<button id="btnSend" type="submit" form="form">OK</button>

发布评论

评论列表(0)

  1. 暂无评论