javascript - Submit form in <a href="form.submit();"> - Stack Overflow

Sorry for asking a weird question...I want to submit a form out of . But I want to allow users to open

Sorry for asking a weird question... I want to submit a form out of . But I want to allow users to open the link in a new tab (e.g Ctrl+Click). Here is what I have already tried.

1 . <a href="#" onclick="document.form1.submit();">Submit Form</a>

This opens the new link in the same tab and the old link in the new tab.

2. <a href="javascript: document.form1.submit();">Submit Form</a>

This does not let the link to be opened in a new tab.

How can I make it right?

Thanks.

Sorry for asking a weird question... I want to submit a form out of . But I want to allow users to open the link in a new tab (e.g Ctrl+Click). Here is what I have already tried.

1 . <a href="#" onclick="document.form1.submit();">Submit Form</a>

This opens the new link in the same tab and the old link in the new tab.

2. <a href="javascript: document.form1.submit();">Submit Form</a>

This does not let the link to be opened in a new tab.

How can I make it right?

Thanks.

Share Improve this question asked Mar 28, 2013 at 10:43 AL̲̳IAL̲̳I 2,4614 gold badges32 silver badges51 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

use the target attribute on form

<form action="demo_form.asp" method="get" target="_blank">
  <input type="submit" value="Submit">
</form>

To open the submission into a new tab, use :

<form name="myform" id='myform' [...] target='_blank'>
[...]
</form>

[TO MAKE NEW TAB OPTIONAL]
If you want, you can add a checkbox, with this code attached :

<a href="#" onclick="document.form1.submit();">Submit Form</a><br />
<input type='checkbox' id='newTabCheck' /> Open in new Tab

And in jQuery

$('#form1').submit(function() {
   if($('#newTabCheck').is(':checked'))
    $('#form1').attr('target', '_blank');
    return true;
});

Or

$('#newTabCheck').change(function() {
   if($(this).is(':checked'))
      $(this).attr('target', '_blank');
   else
      $(this).removeAttr('target');
});

Just put target="_blank" in <form></form> Fields.

ie <form action"your_url" method="post" target="_blank"></form>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743755242a4501639.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信