html – Javascript, viewing [object HTMLInputElement]

html – Javascript, viewing [object HTMLInputElement]

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.

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


See an example in this jsFiddle.

Also, and seeing youre starting to learn HTML, you might consider using console.log() instead of alert() for debugging purposes. It doesnt 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 …)

html – Javascript, viewing [object HTMLInputElement]

Its not because you are using alert, it will happen when use document.write() too. This problem generally arises when you name your id or class of any tag as same as any variable which you are using in you javascript code. Try by changing either the javascript variable name or by changing your tags id/class name.

My code example:

<!doctype html>
    <title>Transaction Tracker</title>
    <script src=bank.js></script> 
        <div><button onclick=bitch()>Press me!</button></div>

Javascript code:

function bitch(){ amt = 0;
var a = Math.random(); ran = Math.floor(a * 100);
return ran; }

function all(){
amt = amt + bitch(); document.write(amt + 
); } setInterval(all,2000);

you can have a look and understand the concept from my code. Here i have used a variable named amt in JS. You just try to run my code. It will work fine but as you put an [id=amt](without square brackets) (which is a variable name in JS code )for div tag in body of html you will see the same error that you are talking about.
So simple solution is to change either the variable name or the id or class name.

Leave a Reply

Your email address will not be published.