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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts

    <input type="image"> Can I get the width and height?

    Hello,

    I succesfully created a javascript function to auto resize the browser window according to the size of the image that is displayed. I retrieved the width and height via document.imagename.width and document.imagename.height. However, I wanted to add a server side onclick event (ASP.NET) - in order for this to work, I had to change the image into an imagebutton (onclick is not supported on an image web control in ASP.NET, that's specifically what the imagebutton control is for). In HTML this imagebutton control translates as an <input type="image"> This of course destroys my javascript, at least the part where I retrieve the correct width and height of the image.

    So my question: is there a way to retrieve the width and height of an image used in an input type="image"? I tried document.formname.imagename.width but that didn't work.
    Last edited by snowieken; 02-03-2009 at 06:09 PM.
    -Snow

    Susie, if you want to see your doll again, leave $100 in this envelope by the tree out front. Do NOT call the police. You CANNOT trace us. You CANNOT find us.

    Sincerely,
    - Calvin.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can add runat="server" to the image and add it as a generic control on the server.

    You can call your own __doPostBack("fooName",""); to make a callback.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts
    Thanks for the answer, Eric.

    What did the trick, however, was document.getElementById("img").offsetWidth, and of course offsetHeight for height. This gave me the original dimensions of the image, which I needed.
    -Snow

    Susie, if you want to see your doll again, leave $100 in this envelope by the tree out front. Do NOT call the police. You CANNOT trace us. You CANNOT find us.

    Sincerely,
    - Calvin.


  •  

    Posting Permissions

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