Multiple onChange image changes

admin

Administrator
Staff member
I don't know how I get myself into these things, especially considering this is just a hobby so far...

Okay, I'm trying to change an image when a certain select field is changed using the onChange function. I got it working with a single select and image, but then I tried to use the function on a different select/image pair, and realized that I had the specific name of the image in the function, so I went about trying to put the image name in a variable depending on which select was used, but can't for the life of me figure it out. Here's the code:

function StatusBar(name)
{
var selected = document.char.name.selectedIndex;
var value = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/selected">http://www.webdeveloper.com/forum/archi ... p/selected</a><!-- m --> + 4;
if ((value == 6) || (value == 7) || (value == 8) || (value == 9))
{
value = "0" + value;
}
if ((value == 5) || (value == 4))
{
return false;
}
var picture = "image/" + value + ".gif";
var which_one = WhichOne(name)
var this_one = "document." + which_one + ".src";
document.char.text.value = this_one;
this_one=picture;
}

function WhichOne(full_name)
{
var one = full_name
if (one == document.char.bra)
{
one = "brains";
return one;
}
else
{
if (one == document.char.coo)
{
one = "cool";
return one;
}
else
{
return false;
}
}
}

I have that in the head, and here's what's in my body:

<form name="char" onSubmit="return false;">
<p>Brains: <select onChange="StatusBar(window.document.char.bra);" name="bra">
<option>Pick
<option>----
<option>06
<option>07
<option>08
<option>09
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
</select>
<img src=http://www.webdeveloper.com/forum/archive/index.php/"../image/black.gif" name="brains"></p>
<p>Cool: <select onChange="StatusBar(window.document.char.coo);" name="coo">
<option>Pick
<option>----
<option>06
<option>07
<option>08
<option>09
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
</select>
<img src="../image/black.gif" name="cool"></p>
</form>

I really should go to school to actually learn this stuff, but who has the money?
 
Back
Top