Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unable to get id of image button

    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:
    Code:
    <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:
    Code:
    <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

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    first charactor of id must not be numeric

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I modified the coding a little:
    Code:
    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?

  • #4
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    it worked for me...
    and i assume that lblURL is the id and NOT the name of the label...
    - NS 666
    .net DEVILoper

  • #5
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    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
    Last edited by vwphillips; 12-17-2005 at 10:50 AM.

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    63
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •