I have a form which is laid out like a spreadsheet.
I want to validate the text in each textbox and if it\'s not numeric, change the background of the textbox and di
// locate all ":input" elements within a generic , // then use .each() to loop through all results $('form :input').each(function(){ var $el = $(this); // element we're testing // attempt to cast the form's value to a number var n = parseFloat($el.val()); // check if the conversion passed if (isNaN(n)){ // $el does not have a number in it } });
I think is what you're after. You can also specify input[type="text"] if you want to be more specific to
input[type="text"]
Or, more concisely:
$('form input[type="text"]').each(function(i,e){ if (isNaN(parseFloat(e.value,10))){ $(e).css('backgroundColor','red'); } });