Highlight input field if value < 0.

This Oracle Apex tutorial shows how to highlight the numeric field if the value is less than 0 using jQuery. The below example will change the foreground color of the numeric field to red if the value is negative (< 0).

Highlight Field (change color) If The Value is < 0 (Negative)

The following jQuery code will check if the input item's value is numeric and it is less than 0, then will change the color to red. Put the below code in the Execute when page load section of the Oracle Apex page:

$('input').each(function(){
    if ($.isNumeric($v(this))) {
        if (parseFloat($v(this),10) < 0) {
           $(this).css({'color':'red'})
        }
    }
}).on('blur', function() {
if ($.isNumeric($v(this))) {
        if (parseFloat($v(this),10) < 0) {
           $(this).css({'color':'red'})
        }
    }
});

Output:

Highlight input field if value < 0.

 

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.

Leave a Reply