Here's what we've learned so far about getting at an image object:
function simpleSwap()
{
var the_image = prompt("change parrot or cheese","");
var the_image_name = "window.document." + the_image;
var the_image_object = eval(the_image_name);
the_image_object.src = "ant.gif";
}
As it turns out, you can refer to images by their name in the images-associative array, like this window.document.images["parrot"].src. This is just like referring to images by their index number in the forms array, as in window.document.images[0].src. Therefore, the above code can be rewritten as
function simpleSwap()
{
var the_image = prompt("change parrot or cheese","");
window.document.images[the_image].src = "ant.gif";
}
You can use this trick to locate all sorts of objects. If you have a textbox in a form, like this:
<form name="the_form">
<input type="text" name="the_text_box">
</form>
You could change the text in the textbox like this: