I want to dynamically set the height and width of an image using javascript so that the image looks proportionally fine according to different screen resolutions…
The original image is of 252*62 pixels…
I have used the following code…but it doesnt seem to work.
<script type="text/javascript">
function resizeheight() {
var height = ((62*screen.height)/800);
return height;
}
function resizewidth() {
var width = ((252*screen.width)/1280);
return width;
}
the width and height attributes in HTML cannot accept javascript as parameters… to do what you are trying to do, you’d have to write out your image WITH the javascript (document.write) or latch onto it by id to resize it. In fact, few if any HTML attributes OTHER than the event based ones accept javascript as parameters.
I’d also point out that you can simply return a value instead of storing it in a variable first.