Introduction
Validation using Javascript, jQuery using the class name.
You just need to add class 'mandatory' in control then this control will be required for submission of the form. if it is not filled then it will be red highlighted.
Code
Validation using Javascript, jQuery using the class name.
You just need to add class 'mandatory' in control then this control will be required for submission of the form. if it is not filled then it will be red highlighted.
Code
- function Validation() {
- var isValid = true;
- var classname = 'mandatory';
- $('.' + classname + '').each(function (i, obj) {
- if (obj.value == '') {
- isValid = false;
- return isValid;
- }
- });
- if (!isValid) {
- $('.' + classname + '').each(function (i, obj) {
- if (obj.value == '') {
- obj.style.border = '1px solid red';
- }
- else {
- obj.style.border = '1px solid black';
- }
- });
- alert('Please fill mandatory details');
- }
- if (isValid) {
- return confirm('Are you sure you want to save information? Once information stored will not be updated.')
- }
- return isValid;
- }
- for ex.
- ASP textbox : <asp:TextBox ID="txtlocation" runat="server" CssClass="form-control mandatory"></asp:TextBox>
- html input text : <input class="mandatory" type="text">