Introduction
This will explain the concept of validation using the class name in Javascript and jQuery. You just need to add the class 'mandatory' in control, then this control will be required for submission of the form. If it is not filled, then it will be highlighted red.
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 Example
ASP textbox :
Sourabh SomaniPosted Jan 10, 2020, 6:59 AM
This is really useless blog. If person come and get help then he will not get the help. First thing I don't know why are you using this ===>+ ''
Rushi MehtaPosted Jan 10, 2020, 1:08 AM
Nice and Useful article
Sourav Kumar DasPosted Jan 9, 2020, 11:07 PM
Nice and useful article.