martynball
03-13-2010, 05:05 PM
I want to print the name of a field on the screen, but it is just printing "[object HTMLInputElement]", which of course is the object. How can I make the JS print the actual name?
function validate(field,txt) {
with (field) {
if (value==null||value=="") {
field.style.borderColor="#c51717";
field.style.color="#c51717";
field.style.backgroundColor="#ffbbbb";
var fname = field;
document.getElementById("errorBox").innerHTML = "<p>Please enter your "+ fname +"!</p>";
return false;
}
else { return true; }
}
}
/*Check whole form for errors*/
function validate_form(thisform) {
/*With the form script was executed from do the following...*/
with (thisform) {
/*Checks if data has been entered into fields*/
if (validate(username,"Your username is required!")==false) {
username.focus();
return false;
}
if (validate(password,"Your password is required!")==false) {
password.focus();
return false;
}
}
}
function validate(field,txt) {
with (field) {
if (value==null||value=="") {
field.style.borderColor="#c51717";
field.style.color="#c51717";
field.style.backgroundColor="#ffbbbb";
var fname = field;
document.getElementById("errorBox").innerHTML = "<p>Please enter your "+ fname +"!</p>";
return false;
}
else { return true; }
}
}
/*Check whole form for errors*/
function validate_form(thisform) {
/*With the form script was executed from do the following...*/
with (thisform) {
/*Checks if data has been entered into fields*/
if (validate(username,"Your username is required!")==false) {
username.focus();
return false;
}
if (validate(password,"Your password is required!")==false) {
password.focus();
return false;
}
}
}