...

View Full Version : Unable to get id of image button



shaoen01
12-17-2005, 09: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:


<script>
function Btn_onClick(control){
window.alert(window.document.getElementById(control.id));
//window.alert(window.event.srcElement);
}
</script>


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

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

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


function Btn_onClick(){
window.alert(window.event.srcElement.id);
lblURL.innerText=window.event.srcElement.id;
}


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?

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

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

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

X browser would be innerHTML

shaoen01
12-17-2005, 04: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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum