|
-
Oct 27th, 2005, 04:36 PM
#1
Thread Starter
yay gay
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/
-
Oct 28th, 2005, 01:23 AM
#2
Frenzied Member
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.
-
Oct 28th, 2005, 07:05 AM
#3
Lively Member
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;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|