Avatar of Opeyemi AbdulRasheed
Opeyemi AbdulRasheed

asked on 

Add Error Class to all Inputs with Zero Values in a DataTable

Hello Experts!

I need help on the following:

Currently, I'm using onblur to do client-side validation on DataTable inputs using this:
$("body").on('blur', 'input[name^="cass"]', function() {
	checkCA(10);
});

$("body").on('blur', 'input[name^="exam"]', function() {
	checkExam(70);
});

function checkCA(max) {
	var currentInput = $(event.target);

	if ( currentInput.val() > max) {

		toastr.error('CA Scores cannot be greater than '+max);
		urrentInput.addClass('invalid');
		} else {
		currentInput.removeClass('invalid');
		}
};

function checkExam(max) {
	var currentInput = $(event.target);

	if ( currentInput.val() > max) {

		toastr.error('Exam Scores cannot be greater than '+max);
		currentInput.addClass('invalid');
		} else {
		currentInput.removeClass('invalid');
		}
};

Open in new window

Now, I want to check Zeros but not onblur. User may not click on a particular input so onblur will not work. I want the border highlighted after the submit button is clicked so as to draw user's attention to the Zero value.

Actually, Zeros are allowed but I still want to show them. If they left it on purpose, it's okay. But what if it was a mistake? That's why I want it highlighted. After all, all inputs will still be available after submit.

Thank you
HTMLPHPjQueryCSSJavaScript

Avatar of undefined
Last Comment
Opeyemi AbdulRasheed
ASKER CERTIFIED SOLUTION
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Opeyemi AbdulRasheed
Opeyemi AbdulRasheed

ASKER

Thank you so much, brother
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Glad to help brother.
Avatar of Opeyemi AbdulRasheed

ASKER

Please, do you suggest I change all other codes where I used same methods to populate DataTable?
I mean change this:
myTable.clear().draw();
myTable.rows.add(data).draw();

Open in new window

To:
myTable.clear();
myTable.rows.add(data.data);
myTable.draw();

Open in new window

?
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo