Reputation: 307
Need to validate label values(get from database) and TextBox values(user enters). If Textbox field value is greater than label value means, have to show error or warning message.
Upvotes: 0
Views: 2009
Reputation: 65351
Here's a simple Javascript validator that does what your looking for.
document.getElementById( 'numbers' ).addEventListener( 'keyup', function ( event ) {
if( event.srcElement.className == 'validate' ) {
var value = event.srcElement.value,
validationValue = event.srcElement.nextSibling.textContent;
if( isNaN( value ) ) {
event.srcElement.nextSibling.className = 'error-nan';
} else if( parseInt( value ) > parseInt( validationValue ) ) {
event.srcElement.nextSibling.className = 'error-too-large';
} else {
event.srcElement.nextSibling.className = '';
};
};
} );
<form id="numbers">
<input class="validate" /><label>15</label><br />
<input class="validate" /><label>7</label><br />
</form>
.error-too-large::after {
color: red;
content: 'value too large';
padding-left: 5px;
}
.error-nan::after {
color: red;
content: 'value not a number';
padding-left: 5px;
}
Upvotes: 1
Reputation: 8637
You can use ASP.NET Validation Controls. They use client and server validation.
Upvotes: 0