Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, viewing [object HTMLInputElement]

I'm just started to learn HTML. Doing an alert() on one of my variables gives me this result [object HTMLInputElement].

How to get the data, that were added in text field, where my input type is text?

like image 572
iPhoneDeveloper Avatar asked Mar 13 '13 11:03

iPhoneDeveloper


2 Answers

Say your variable is myNode, you can do myNode.value to retrieve the value of input elements.

Chrome Developer Tools has a Properties tab which shows useful DOM attributes.

Also see MDN for a reference.

like image 90
simonzack Avatar answered Sep 17 '22 13:09

simonzack


If the element is an <input type="text">, you should query the value attribute:

alert(element.value); 

See an example in this jsFiddle.

Also, and seeing you're starting to learn HTML, you might consider using console.log() instead of alert() for debugging purposes. It doesn't interrupt the execution flow of the script, and you can have a general view of all logs in almost every browser with developer tools (except that one, obviously).

And of course, you could consider using a web development tool like Firebug, for instance, which is a powerful addon for Firefox that provides a lot of functionalities (debugging javascript code, DOM inspector, real-time DOM/CSS changes, request monitoring ...)

like image 43
Xavi López Avatar answered Sep 19 '22 13:09

Xavi López