2

For some reason I don't get why my form is not submitting using $( "#target" ).submit();.

<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js'></script>    
<script>
function saveItem()
{
    console.log($("#frm"));
    $("#frm").submit();
}
</script>
</head>
<body>
<form id="frm" action="form.php" method="post">
    <a href="javascript:;" title="Save" onclick="saveItem()">save</a>
    <button type="submit" id="submit">Save</button>        
</form>
</body>
</html>
anjanesh
  • 3,771
  • 7
  • 44
  • 58

2 Answers2

3

id attribute cannot be submit in the form element try another name .

why we shouldn't set id as submit ?

because If a form control (such as a submit button) has a name or id of submit it will mask the form's submit method.

Mahi
  • 1,707
  • 11
  • 22
  • It can but it shouldn't for any element nested inside a `form`. BTW, it is the same for `name` attribute. EDIT: i didn't downvoted it... – A. Wolff Dec 05 '16 at 12:45
0

<form id="frm" action="form.php" method="post">
    <a href="#" title="Save" onclick="saveItem()">save</a>
</form>

Delete submit button if you want submit form by JS. And change element type,

<span>

for example.

Artem Ilchenko
  • 1,050
  • 9
  • 20