View Single Post
Old 09-05-2012, 08:01 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
1. Why are you trying to use .id if you want to access the value? Why not use .value?
2. In II: You assigned an event handler using one of the onxxxxx attributes. In that case the context for the function does not change to be a reference to the DOM object, so "this" will be a reference to the window object instead.
3. In III: getElementsByTagName (mind the 's') will return a collection of DOM objects which is essentially an array. In order to retrieve the first object from the array, you will have to use the index [0] on it
Code:
<input type="button" id="btn1" value="A" onclick="showValue(this)"/>


function showValue(obj) {
   alert(obj.value);
}
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
clathrun (09-06-2012)