javascript - what does this.id return? -
function test(){ alert(this);//alerts oblect alert(this.id);//alerts undefined } <input type="text" onkeypress="test();" id="text1">
why alert(this.id) alert undefined? because this returns document object?
thank you
your code should be.
function test(objref){ alert(objref);//alerts oblect alert(objref.id);//alerts undefined } <input type="text" onkeypress="test(this);" id="txtnum" />
edit: may use following code too.
<script type="text/javascript"> window.onload = function() { var txtnum = document.getelementbyid("txtnum"); txtnum.onkeypress = function() { alert(this); alert(this.id); }; }; </script> <input type="text" id="txtnum" />
Comments
Post a Comment