Robert Granlund
asked on
jQuery Each()
I have a form with 4 text input fields that I need to make sure are numeric. Each input field has a class of .laser_numeric and the form ID is #laser_finder.
Each time there is a change on th form I want to check to make sure it is either numeric or empty. If any are not numeric (Alpha) I open an Overlay with a message box. The message box can be closed.
The following code only works on the first field with the class .laser_numeric. I need it to work on all four.
Help?
Each time there is a change on th form I want to check to make sure it is either numeric or empty. If any are not numeric (Alpha) I open an Overlay with a message box. The message box can be closed.
The following code only works on the first field with the class .laser_numeric. I need it to work on all four.
Help?
$(function () {
$("#laser_finder").change(function(e) {
var director = $("input.laser_numeric").val();
if(director=="" || ($.isNumeric($('input.laser_numeric').val()))){
return true;
} else {
e.preventDefault();
$('body').append(
$('<div/>')
.addClass('overlay')
.height(
$(document).height()
)
);
$('#numeric_values').fadeIn();
$('#close-dialog').click(function() {
$('div.overlay').remove();
$('#numeric_values').fadeOut();
});
return false;
}
});
});
ASKER
How do I add a decimal point to:
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
return true;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
But if you insist on using your script, the solution is to use the class name of the inputs rather than the id of the form as in this jsfiddle example.