Oracle Apex - Highlight Numeric Field If Less Than 0 Using jQuery

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:

 

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.