I have 3 textboxes

names

myTextBox1
myTextBox2
myTextBox3

onblur i want to check if the value of the checkbox is true.

I have a function in my js file.

function isNumeric(myString) {.......}

In my JSP file i write;

onblur="isNumeric(X)"

I wrote everything and it does not work. What must i have write instead of X.? The id of the checkbox? The name?

I also use onchange for my textboxes...

Dani AI

Generated

Short answer: the blur handler needs an actual input element or its value, and the cleanest, most maintainable approach is to attach listeners in script and read event.target.value. was on the right track about passing the value — that will work — but moving validation into a script listener avoids brittle inline attributes and makes debugging easier.

A modern, minimal pattern (attach by class/id and validate on blur) looks like this:

<input class="num" id="n1">
<input class="num" id="n2">
<input class="num" id="n3">
document.querySelectorAll('.num').forEach(function(el) {
  el.addEventListener('blur', function(e) {
    var v = e.target.value.trim();
    if (!isNumericValue(v)) el.classList.add('invalid');
    else el.classList.remove('invalid');
  });
});

function isNumericValue(s) {
  if (s === '') return false;
  return /^-?\d+(\.\d+)?$/.test(s); // integer or decimal, optional minus
}

Alternate validator using numeric coercion:

function isNumericValue(s) {
  s = s.trim();
  return s !== '' && Number.isFinite(Number(s));
}

Practical tips: give inputs an id (client-side selection) and/or a shared class; name is for form submission, not DOM lookup. Use oninput if you want live feedback, onchange only after a change+blur, and blur whenever focus is lost. Check that your JS file is actually loaded (watch the browser console), and consider HTML5 type="number" for built-in UI/validation (see MDN: input type=number). For parsing/edge cases read about addEventListener and Number.isFinite on MDN: addEventListener and Number.isFinite.

Try this:

onBlur="isNumeric(this.value)"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.