Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q668 How can I swap an image out based on what someone selects from a select box?

You are here: irt.org | FAQ | JavaScript | Image | Q668 [ previous next ]

Try:

<IMG SRC="default.gif" NAME="myImage">

<SCRIPT LANGUAGE="JavaScript"><!--
function change(what) {
    value = what.options[what.selectedIndex].value;
    if (value != '')
        if (document.images)
            document.images['myImage'].src = value;
}
//--></SCRIPT>

<FORM>
<SELECT onChange="change(this)">
<OPTION>Select an animal:
<OPTION VALUE="chicken.gif">Chicken
<OPTION VALUE="cat.gif">Cat
<OPTION VALUE="bear.gif">Bear
</SELECT>
</FORM>

Feedback on 'Q668 How can I swap an image out based on what someone selects from a select box?'

©2018 Martin Webb