...

View Full Version : [object HTMLInputElement]



martynball
03-13-2010, 06: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;
}
}
}

d_s
03-13-2010, 06:14 PM
Hi,

I came to know that you are passing the field as an argument to the validate function.

For this purpose, we can use the "field.value" to get the content of that field. It is evident that you have used the field as such in the statement. If you call the "value" property for that control, you will get this solved.

Hope this reply is used in solving this problem of yours...

For any further javascript related concepts, you may visit my blog at : http://www.dsaravanan.wordpress.com/javascript.

Regards

d_s

martynball
03-13-2010, 06:38 PM
I understand how to get the value, but I do not want the value. I want the NAME of the field to be displayed as the value would be blank...

martynball
03-13-2010, 06:59 PM
Nevermind, done it. Common sence tbqh... just add .name on the end instead of .value

Dammit, why does code have to make some things simple but then other things which seem more simple harder lmfao.

Dormilich
03-13-2010, 08:06 PM
Dammit, why does code have to make some things simple but then other things which seem more simple harder lmfao.

because the humanís mind is twisted. if you think like a computer, everything is simple.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum