To grab the value of an item as you blur, you should add the onBlur
trigger to the DOM element as follows:
<input type="text" name="validate_me" onBlur="valid(this);" />
That way you have access to the DOM element that triggered the onBlur
event and can access its properties (such as value
or innerHTML
in the case of textarea
elements.
Your valid
function can then be something like:
function valid(element) {
if (element.value != '' && isNaN(element.value))
alert('This field is not valid!');
};