I have a normal form which looks like this:
<form id="selectionForm" class="form-horizontal">
<div>
<div class="form-group row">
<div class="col-md-4 form-group">
<label for="selectionDate">Selection
Date</label>
<input type="text" id="selectionDate" name="selectionDate" class="nepali-calendar ndp-nepali-calendar form-control" onfocus="showNdpCalendarBox('selectionDate')" required >
<div style="margin: 10px;"></div>
</div>
<div class="col-md-4 form-group">
<label class="col-md-12" for="selectedBy">Selected By</label> <label
class="col-md-6"> <input style="margin: 10px;"
type="radio" name="selectedBy" value="Department" required />Department
</label>
<label class="col-md-6">
<input style="margin: 10px;"
type="radio" name="selectedBy" value="Office" required />Office
<div style="margin: 10px;"></div>
</label>
</div>
<div class="form-group col-md-4">
<label for="panEximNumber">PAN/EXIM Number</label> <input
type="text" id="panEximNumber" class="form-control"
name="eximPanNo" placeholder="Enter the PanEximNumber" pattern=".{9,10}" title="Characters must be only 9 characters" required >
</div>
</div>
<div class="form-group row">
<div class="form-group col-md-4">
<label for="paneximnepali">PAN/EXIM Name(Nepali)</label> <font
face="pcs"> <input type="text" id="panEximNameNepali"
class="form-control" name="eximPanName"
placeholder="Enter the name" required></font>
</div>
<div class="form-group col-md-4">
<label for="paneximeng">PAN/EXIM Name(English)</label> <input
type="text" id="paneximEnglish" class="form-control"
name="eximPanNameEng"
placeholder="Enter the Pan Exim Name(English)" required>
</div>
<div class="form-group col-md-4">
<label for="age">Exim/Pan Address(Nepali)</label> <font
face="pcs"> <input type="text" id="address"
class="form-control" name="eximPanAddr"
placeholder="Enter the address" required>
</font>
</div>
</div>
<!--row 3-->
<div class="form-group row">
<div class="form-group col-md-4">
<label for="age">Exim/Pan Address(English)</label> <input
type="text" id="address" class="form-control"
name="eximPanAddrEng" placeholder="Enter the address(English)" required>
</div>
<div class="form-group col-md-4">
<label for="age">Exim/Pan Phone Number</label> <input type="text"
id="phoneNumber" class="form-control" name="eximPanPhone"
placeholder="Enter the Phone number" required>
</div>
<div class="form-group col-md-4">
<label for="selectionType">Selection Type</label>
<select
class="form-control" id="selectionType" name="selectionType" required>
<option value="" selected disabled hidden>Choose here</option>
<option value="firm">Firm</option>
<option value="consignment">Consignment</option>
<option value="product">Product</option>
</select>
</div>
</div>
<!--row 4-->
<div class="form-group row">
<div class="form-group col-md-4 consNo" id="consNo">
<label for="consignentNo">Consignment No</label> <input
type="text" id="consignentNo" class="form-control"
placeholder="Enter the consignment No" name="consignmentNo" />
</div>
<div class="form-group col-md-4 consDate">
<label for="consignentDate">Consignment Date</label> <input
type="text" id="consignentDate"
class="nepali-calendar ndp-nepali-calendar form-control"
onfocus="showNdpCalendarBox('consignentDate')"
name="consignmentDate" placeholder="Enter the consignment date" />
</div>
<div class="form-group col-md-4 prodName">
<label for="selectionProductName">Product Name</label> <input
type="text" id="productName" class="form-control"
name="productName" placeholder="Enter the product Name" />
</div>
</div>
<button type="submit" style="margin-bottom: 50px;"
class="btn btn-success pull-right" onclick="submitSelection();">Submit</button>
</div>
</form>
My button to go to the submit action is :
I have added the required field and also other html5 validation properties. When the Submit button is clicked the form submission method is clicked.So,I tried the following to validate but it is not working.
<button type="submit" style="margin-bottom: 50px;"
class="btn btn-success pull-right" onclick="submitSelection();">Submit</button>
And the code to perform the submit operation is:
function submitSelection() {
document.selectionForm.submit();
event.preventDefault();
$.ajax({
//ajax code to submit operation
});
}
I tried to tigger the validation operation by document.selectionForm.submit(); but it is not working.I need to validate my form before submitting through AJAX.How to validate the form?