Results 1 to 3 of 3

Thread: Images and javascript

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Images and javascript

    I have the following code:
    <img src="http://vbforums.com/images/misc/subscribed.gif" onload="CheckFunction('xxx')" width="15" height="15" border="0" id="xxx">
    and then i have the function that is called in the onload event that is CheckFunction that is a little big and it doesnt matter. The thing that matters is the following:
    var item = window.document.getElementsByName(id);
    alert(item.width);
    this surprisingly will said that the width value is undefined , even knowing that i have declared it up there in the html code. what am i doing wrong? I want to be able to change the size of the picture with this function and it shouldnt be hard to do it! should it?
    \m/\m/

  2. #2
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Images and javascript

    PT Exorcist:

    "... i have declared it up there in the html code."

    Your statements ... width="15" height="15" ... do not declare variables. They are attributes of the Image tag.

    I'm not a JavaScript expert, but I think the only way you can change the Image attribute is by using the Dom attribute interface.

    Someone else may have a better solution for you.

  3. #3
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: Images and javascript

    document.getElementsByName() returns a collection, therefore having just item.width wouldn't work. item[id] or item[0] might work. But why not just use document.getElementById()? I think something like this would work out:
    Code:
    function SizeMe(el)
    {
    	var img = document.getElementById(el);
    	alert(img.width);
    }
    
    ....
    <img src="http://vbforums.com/images/misc/subscribed.gif" onload="SizeMe(this.id);" width="15" height="15" border="0" id="xxx">
    Good luck;
    {yak}

Posting Permissions

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



Click Here to Expand Forum to Full Width