is undefined error
Posted: Tue Mar 13, 2012 3:28 am
I have a javascript function that checks whether a field is empty or not; the html code
The javascript in question
The error message is receive from the error console is fieldName is undefined; Any ideas? The code works if i replace 'field' with 'name' but i would like the function to be reuseable.
Thanks in advance
Code: Select all
<label id="name">Name (*)</label>
<input id="fieldName" maxlength="30" name="name" size="30" onblur="return emptyFieldCheck('name');" type="name" />
Code: Select all
function emptyFieldCheck(field)
{
var myForm = document.forms[1];
var fieldName = myForm.field;
var textField = fieldName.value;
if (textField == '') {
alert('Error message');
return false;
}
return true;
}
Thanks in advance