Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > <img> width height

Reply
Thread Tools

<img> width height

 
 
News
Guest
Posts: n/a
 
      04-21-2006
I am trying to be able to manipulate the width and height of an <img> but do
not seem to be able.

"Yes", I know the JavaScript will "not" manip anything, which is ok. I
simply do not know how to capture the width or height. Once I can do that I
can manipulate them.

Here is the HTML for the <img>
<div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">
<img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
</div>

Here is the JavaScript I tried to manipulate the <img>
function imgSize(myID,myImg)
{
var myDiv= document.getElementById(myID); //get correct <div>
var myImage=document.getElementById(myImg); //get correct <img>
var myWidth=myImage.style.width; //attempt to capture width of <img>
var myHeight=myHeight.style.height; //attempt to capture height of <img>
alert("myWidth+, +myHeight"); //show if I this function works
}

Will someone please tell me what I am doing wrong

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW


 
Reply With Quote
 
 
 
 
test
Guest
Posts: n/a
 
      04-21-2006
On Fri, 21 Apr 2006 21:46:37 GMT, News wrote:

> I am trying to be able to manipulate the width and height of an <img> but do
> not seem to be able.
>
> "Yes", I know the JavaScript will "not" manip anything, which is ok. I
> simply do not know how to capture the width or height. Once I can do that I
> can manipulate them.
>
> Here is the HTML for the <img>
> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">


There is a syntax error in this line, near the end. You're
missing an apostrophe. It should go:

<div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg');">

Don't know if that was what was breaking the code though.
 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      04-21-2006
News a écrit :
> I am trying to be able to manipulate the width and height of an <img> but do
> not seem to be able.


> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">
> <img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
> </div>
>
> Here is the JavaScript I tried to manipulate the <img>
> function imgSize(myID,myImg)
> {
> var myDiv= document.getElementById(myID); //get correct <div>
> var myImage=document.getElementById(myImg); //get correct <img>
> var myWidth=myImage.style.width; //attempt to capture width of <img>
> var myHeight=myHeight.style.height; //attempt to capture height of <img>
> alert("myWidth+, +myHeight"); //show if I this function works
> }
>
> Will someone please tell me what I am doing wrong


simplest way :

<img src="pict.jpg"
onmousover="alert('width = '+this.width+' height = '+this.height)";>

maybe your code would be better with :

var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
myImage.width; //attempt to capture width of <img>
var myWidth= myImage.style&&myImage.style.height? myImage.style.height :
myImage.height; //attempt to capture height of <img>

idea :
If your image didn't get a width or height style, you can't catch it.

--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
News
Guest
Posts: n/a
 
      04-21-2006
test wrote:
> On Fri, 21 Apr 2006 21:46:37 GMT, News wrote:
>
>> I am trying to be able to manipulate the width and height of an
>> <img> but do not seem to be able.
>>
>> "Yes", I know the JavaScript will "not" manip anything, which is ok.
>> I simply do not know how to capture the width or height. Once I can
>> do that I can manipulate them.
>>
>> Here is the HTML for the <img>
>> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">

>
> There is a syntax error in this line, near the end. You're
> missing an apostrophe. It should go:
>
> <div class="ImgMnp" id="myImg"
> onmouseover="imgSize('myImg','fpImg');">
>
> Don't know if that was what was breaking the code though.


I did not know I need that apostrophe thanks.

Nope did not correct the problem, if I take out these two lines

var myWidth=myImage.style.width;
var myHeight=myHeight.style.height;

the function works, put them in the function crashes.
--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW


 
Reply With Quote
 
News
Guest
Posts: n/a
 
      04-21-2006
ASM wrote:
> News a écrit :
>> I am trying to be able to manipulate the width and height of an
>> <img> but do not seem to be able.

>
>> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">
>> <img src="images/FirePlace.jpg" width="480" height="640" id="fpImg"
>> /> </div>
>>
>> Here is the JavaScript I tried to manipulate the <img>
>> function imgSize(myID,myImg)
>> {
>> var myDiv= document.getElementById(myID); //get correct <div>
>> var myImage=document.getElementById(myImg); //get correct <img>
>> var myWidth=myImage.style.width; //attempt to capture width of
>> <img> var myHeight=myHeight.style.height; //attempt to capture
>> height of <img> alert("myWidth+, +myHeight"); //show if I this
>> function works }
>>
>> Will someone please tell me what I am doing wrong

>
> simplest way :
>
> <img src="pict.jpg"
> onmousover="alert('width = '+this.width+' height = '+this.height)";>
>
> maybe your code would be better with :
>
> var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
> myImage.width; //attempt to capture width of <img>
> var myWidth= myImage.style&&myImage.style.height?
> myImage.style.height : myImage.height; //attempt to capture height
> of <img>
> idea :
> If your image didn't get a width or height style, you can't catch it.


What does this mean??
> var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
> myImage.width; //attempt to capture width of <img>


At first I thought it was a triune if true this else that type statement but
I don't have a clue what it is.


--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW


 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      04-22-2006
News a écrit :
>
> Nope did not correct the problem, if I take out these two lines
>
> var myWidth=myImage.style.width;
> var myHeight=myHeight.style.height;


Hu ?

myHeight=myHeight

from where comes this 2nd myHeight ?

would be better with the image 'myImag' , no ?

var myWidth=myImage.style.width; //attempt to capture width of <img>
var myHeight=myImage.style.height; //attempt to capture height of <img>
// ^^^^^^^
alert("myWidth+, +myHeight"); //show if I this function works
}


--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      04-22-2006
News a écrit :
>
> What does this mean??
>
>>var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
>> myImage.width; //attempt to capture width of <img>

>
> At first I thought it was a triune if true this else that type statement but
> I don't have a clue what it is.


yes it was (would have to be).

if myImage has style and myImage has style width,
miWidth is myImage.style.width
else
miWidth is myImage width

because perhaps your image has no style (or no width or height style) ?

in fact the error was much more stupid
(all as I've done in my code myWidth=myImage.style.height ! !)

--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
News
Guest
Posts: n/a
 
      04-22-2006
ASM wrote:
> News a écrit :
>>
>> Nope did not correct the problem, if I take out these two lines
>>
>> var myWidth=myImage.style.width;
>> var myHeight=myHeight.style.height;

>
> Hu ?
>
> myHeight=myHeight
>
> from where comes this 2nd myHeight ?
>
> would be better with the image 'myImag' , no ?
>
> var myWidth=myImage.style.width; //attempt to capture width of <img>
> var myHeight=myImage.style.height; //attempt to capture height of
> <img> // ^^^^^^^
> alert("myWidth+, +myHeight"); //show if I this function works
> }


Greif I HATE it when I make stupid mistakes and simply cannot see them. Yup
it works and I have egg on my face.

Thanks and have a great weekend


--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW


 
Reply With Quote
 
News
Guest
Posts: n/a
 
      04-22-2006
ASM wrote:
> News a écrit :
>>
>> What does this mean??
>>
>>> var myWidth= myImage.style&&myImage.style.width?
>>> myImage.style.width : myImage.width; //attempt to capture width of
>>> <img>

>>
>> At first I thought it was a triune if true this else that type
>> statement but I don't have a clue what it is.

>
> yes it was (would have to be).
>
> if myImage has style and myImage has style width,
> miWidth is myImage.style.width
> else
> miWidth is myImage width
>
> because perhaps your image has no style (or no width or height style)
> ?
> in fact the error was much more stupid
> (all as I've done in my code myWidth=myImage.style.height ! !)


I hope one day I will be able to avoid stupid mistakes or at the very least
find them before I air them to the WORLD

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW


 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      04-22-2006
News a écrit :
>
> I hope one day I will be able to avoid stupid mistakes or at the very least
> find them before I air them to the WORLD


You may spend a long time runing around a stupid mistake
more they are stupid more it is difficult to find them

a new eye cand find them in seconds

ngs are there for that too.

--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can't I change height with <col width="50" height="100">? Bernd Meier HTML 6 01-14-2008 07:25 AM
CSS question: Using height/width at 100% with fixed-width borders/margin/padding cera HTML 1 08-18-2007 02:59 AM
how to get specific cell height without hard-coding a height value laredotornado@zipmail.com HTML 0 08-19-2006 08:13 PM
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
CSS min-width, max-width, and min-height with display:inline Lois HTML 1 12-27-2004 03:03 AM



Advertisments