Click to See Complete Forum and Search --> : resizing an image using radio buttons?


Lon
08-26-2003, 09:40 AM
:confused: I have been trying to write a little script to change an image size by percent using radio buttons? I don't need to use radio buttons but only want to give an exact input that a button would give me. My script in "HTML" is below. (it don't work yet)......

<form name="cSize" method="document">
<input name="percent" type="radio" value="40%">40% (Smaller)<br>
<input name="percent" type="radio" checked value="50%">50% (good)<br>
<input name="percent" type="radio" value="70%">70% (Bigger)<br>

<img src="lon 004.jpg" getimagesize("lon 004.jpg");width="auto" height="percent" alt="004">
</form>

can anyone help with this? I think that it needs to be done in java?
Lon

freefall
08-31-2003, 08:56 PM
Hello! Actually this can be done with a simple javascript.

<input name="percent" type="radio" onclick="resize('lon 004',40);">40% (Smaller)<br>
<input name="percent" type="radio" onclick="resize('lon 004',50);" checked>50% (good)<br>
<input name="percent" type="radio" onclick="resize('lon 004',70);">70% (Bigger)<br>

<img name="lon 004" src="lon 004.jpg" width=416 height=200 alt="lon 004">


<script type="text/javascript">
var w = document.getElementById("lon 004").width;
var h = document.getElementById("lon 004").height;

function resize(elem, percent)
{
percent *= .01;
document.getElementById(elem).width = w * percent;
document.getElementById(elem).height = h * percent
}
</script>

I think this is something like what you described. All this does is collect the percentage you want the image to be multiplied by. If you have any questions, please ask and I can describe what each part of the code does and how you can modify it.

Good luck and God bless
Ian Paterson