Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    [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; 
    		 }
    	}
    }

  • #2
    d_s
    d_s is offline
    New Coder
    Join Date
    Mar 2010
    Location
    India
    Posts
    52
    Thanks
    0
    Thanked 8 Times in 8 Posts

    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

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    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...

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    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.

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,471
    Thanks
    13
    Thanked 361 Times in 357 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •