View Full Version : Unable to get id of image button

12-17-2005, 10:14 AM
I wish to get the id of the <input type="image"> in the client-side before it generate the postback in the server-side. However, i always received a "null" or "[Object]", which is displayed using the "window.alert()" method.

This is my coding used to create the image button:

<input type="Image" name="1.jpg" id="1.jpg" onclick="Btn1_onClick(this)" src=Images/1.jpg class="removeBorder" onmouseover="this.className='applyBorder'"
onmouseout="this.className='removeBorder'" />"

Below is the Btn1_onClick() which is called onclick:

function Btn_onClick(control){

I have also tried using the "window.document.getElementsByTagName(tag)", "window.document.getElementsByName(name)" and "window.event.srcElement", but still return the "[object]" message.

Btw, i am creating a user control (.ascx) in ASP.net, therefore i wont be able to use <form> tags, if this information is of any help. Thanks

12-17-2005, 10:22 AM
first charactor of id must not be numeric

12-17-2005, 10:48 AM
I modified the coding a little:

function Btn_onClick(){

And was able to display the id of the element using a message box but the problem now is that i cant get it to write to my label, lblURL. Do you know why?

12-17-2005, 11:43 AM
it worked for me...
and i assume that lblURL is the id and NOT the name of the label...

12-17-2005, 11:45 AM
you code & terminerlogy is IE only

what do you want to 'write' (again a strange word to use)?
I see you want to change the text

X browser would be innerHTML

12-17-2005, 05:14 PM
Nischumacher: lblURL is the id of my label.

vwphillips: Yeah, your right. The "innerText" does not work in my IE6 for some reason. I changed it to "innerHTML" and it works fine. However, i edit the text during javascript. When there is a postback, my label text disappears. Do you know why?