I have a simple html form when i try to submit the form this is not submitting. but when i remove one field it submitting. can you help what is cause.
<form name="f2" id="f2" method="post" action="coaching-institute-registrationck.php" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-6">
<span class="error">*</span> <input name="name" id="name" type="text" class="text-field-select-small4" placeholder="Contact Person" required>
</div>
<div class="col-lg-6">
<span class="error">*</span> <input name="business_name" id="business_name" type="text" class="text-field-select-small4" placeholder="Name of Business">
</div>
</div><br>
</form>
when i remove the second field it submitted but when i use the code as written above, the form is not submitting.
Add a submit button at the end of the form to trigger the form action
<input type="submit" name="login" value="Submit"/>
For example
<form name="f2" id="f2" method="post" action="coaching-institute-registrationck.php" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-5">
<span class="error">*</span> <input name="name" id="name" type="text" class="text-field-select-small4" placeholder="Contact Person" required>
</div>
<div class="col-lg-5">
<span class="error">*</span> <input name="business_name" id="business_name" type="text" class="text-field-select-small4" placeholder="Name of Business">
</div>
<div class="col-lg-2"><input type="submit" name="submit" value="Submit"/></div>
</div><br>
</form>
This would seem an easy enough fix to submit the form, when a "enter" is pressed on a textbox:
document.getElementById("#name").addEventListener("keydown",function(e){
if (!e) var e = window.event;
e.preventDefault();
if (e.keyCode == 13){
document.getElementById("#f2").submit();
};
}, false);
Basically, when enter is pressed on your first input textbox, we'll fire the submission function for the form.
To implement this on the second input textbox, simply switch the ID's.
See implicit submission in the HTML specification:
If the form has no Submit Button, then the implicit submission mechanism must do nothing if the form has more than one field that blocks implicit submission, and must submit the form element from the form element itself otherwise.
Since you have no submit button, adding a second text input will block implicit submission.
So you have two choices:
I strongly recommend the former, and it is simpler, easier, and gives a clear UI feature to tell the user that they can submit the form by clicking a button (not all users will realise they can submit forms by pressing Enter).