Click to See Complete Forum and Search --> : dynamic image change


witold
07-26-2003, 06:36 PM
Hi,

I'd like to print an image depending on the value change in a dropdown list

<SELECT NAME="m1" size="1">
<option value="1" selected>img1</option>
<option value="2">img2</option>
<option value="3">img3</option>
</SELECT>

I use the following coding to make the image change, but nothing happens. I obviously miss somthing, but have no idea what.

if (window.document.form.m1.value == 1) {
document.images.show.src = "img1.jpg";
}
if (window.document.form.m1.value == 2) {
document.images.show.src = "img2.jpg";
}
document.write ('<img.src="" name="show">');

maybe I need some onChange action... hope someone gives me a hint.

witold

Charles
07-26-2003, 07:16 PM
1) You cannot write to a ducument once it is parsed and displayed.

2) You are creating a JavaScript dependant page which is a bad thing. But ...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<img alt="[Bettie Paige]" id="bettie" src="http://www.bettiepage.com./images/photos/bikini/bikini1.jpg">
<select onchange="document.getElementById('bettie').setAttribute('src', this.value)">
<option value="http://www.bettiepage.com./images/photos/bikini/bikini1.jpg">1</option>
<option value="http://www.bettiepage.com./images/photos/bikini/bikini2.jpg">2</option>
<option value="http://www.bettiepage.com./images/photos/bikini/bikini3.jpg">3</option>
<option value="http://www.bettiepage.com./images/photos/bikini/bikini4.jpg">4</option>
</select>

geen
07-26-2003, 07:39 PM
I was prepared to respond something like previous reponse :)

Dorin
http://host.domain.name