2

I have a single input outside the form

<input id="BrId" name="BrId" type="text" value="1">

HTML Form-

 <form id="photoform" enctype="multipart/form-data" method="post" action="server-side-path">
    <input type="file" id="Photos" name="photo"/>
    <input type="hidden" name="VisitGuid" value="5" />
    <input type="hidden" name="HiddenBrId" id="HiddenBrId" value="" />
    <input type="submit" />

JQuery-

$('#photoform').on('submit', function (e) { 
     e.preventDefault();
     $('#HiddenBrId').val($('#BrId').val());
     $('#photoform').submit();
});

When I click on submit button, form is not being submitted and console says Uncaught RangeError: Maximum call stack size exceeded

Any help?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168

3 Answers3

2

Cause

$('#photoform').on('submit', function (e) { //S-1
. . . 
 $('#photoform').submit(); //This is the cause, it again calls  "S-1" 
});

Please explain what you actually want to achieve.

Madhu
  • 2,416
  • 3
  • 15
  • 33
2
<form id="photoform" enctype="multipart/form-data" method="post" action="server-side-path">
    <input type="file" id="Photos" name="photo"/>
    <input type="hidden" name="VisitGuid" value="5" />
    <input type="hidden" name="HiddenBrId" id="HiddenBrId" value="" />
    <input type="submit" name="submit_btn" />
</form>

<script>
$('#photoform').on('submit', function (e) { 
     e.preventDefault();
     $('#HiddenBrId').val($('#BrId').val());
     // Change is here
     $('#photoform')[0].submit();
});
</script>

NOTE : Please avoid to use submit and reset as value of name and id attribute of any from input.

AsgarAli
  • 2,201
  • 1
  • 20
  • 32
  • 1
    This doesn't answer the actual question. You should add why that was happening and how does this solves the issue. Although this solves the issue but not a clear answer. – Jai May 10 '16 at 08:00
1
$('#photoform').on('submit', function (e) { 
     e.preventDefault();
     $('#HiddenBrId').val($('#BrId').val());
     // Change is here
     $('#photoform')[0].submit();
});
AsgarAli
  • 2,201
  • 1
  • 20
  • 32