Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-13-2010, 05:05 PM   PM User | #1
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 554
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
[object HTMLInputElement]

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?

Code:
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; 
		 }
	}
}
martynball is offline   Reply With Quote
Old 03-13-2010, 05:14 PM   PM User | #2
d_s
New Coder

 
Join Date: Mar 2010
Location: India
Posts: 52
Thanks: 0
Thanked 8 Times in 8 Posts
d_s has a little shameless behaviour in the past
Smile printing the value of [object HTMLInputElement] - Reg

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
d_s is offline   Reply With Quote
Old 03-13-2010, 05:38 PM   PM User | #3
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 554
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
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 is offline   Reply With Quote
Old 03-13-2010, 05:59 PM   PM User | #4
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 554
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
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.
martynball is offline   Reply With Quote
Old 03-13-2010, 07:06 PM   PM User | #5
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
Quote:
Originally Posted by martynball View Post
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.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:32 AM.


Advertisement
Log in to turn off these ads.