img width

G

Glen Watkins

Function setToWidth()
{
var x = 0
.........code......code........code.........
return x;
}

<body>
document.write("<IMG SRC='myimage.jpg' width='setToWidth()' height='100'>");
</body>

------

I was hoping to set the width to the returned value from the function.

The function was tested and works perfectly.

Any help would be appreciated.

Thanks
 
G

Glen Watkins

Thanks, but unfortunately that didn't work.


Safalra (Stephen Morley) said:
[...]
document.write("<IMG SRC='myimage.jpg' width='setToWidth()' height='100'>");
[...]
I was hoping to set the width to the returned value from the function.


You've put the function call inside the string literal. Try instead:


document.write('<img src="myimage.jpg" width="' + setToWidth() +'"
height="100" alt="Alt text here"');


By the way, document.write is a very old fashioned way of modifying the
document - try reading up on the DOM.


--
Safalra (Stephen Morley)

Sortable Tables In JavaScript:
http://www.safalra.com/web-design/javascript/sortable-tables/
 
S

Stevo

Safalra said:
By the way, document.write is a very old fashioned way of modifying the
document - try reading up on the DOM.

No it isn't.

Firstly, document.write does not "modify" the document, it's used while
the document is being parsed/created and only "adds" to the document, it
doesn't "modify" it. For this purpose it's as current now as it's ever
been, it's not old-fashioned at all. There is no better way.

Secondly, if you're talking about "modifying" the document, then you're
talking about AFTER the page has loaded. In which case, document.write
doesn't work now, nor has it ever.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top