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

Q444 How do I link an image to several different .wav files, depending on which one the user has selected in a list box?

You are here: irt.org | FAQ | JavaScript | Sound | Q444 [ previous next ]

Try this:

<FORM NAME="myform">
<SELECT NAME="myselect">
<OPTION VALUE="afile1.wav">file 1
<OPTION VALUE="afile2.wav">file 2
<OPTION VALUE="afile3.wav">file 3
</SELECT>
</FORM>

<SCRIPT LANGUAGE="JavaScript"><!--
function mytune() {
    location.href = document.myform.myselect.options[document.myform.myselect.selectedIndex].value;
}
//--></SCRIPT>

<A HREF="javascript:mytune()"><IMG SRC="apicture.gif" HEIGHT="100" WIDTH="100" BORDER="0"></A>

Or:

<FORM NAME="myform">
<SELECT NAME="myselect">
<OPTION VALUE="afile1.wav">file 1
<OPTION VALUE="afile2.wav">file 2
<OPTION VALUE="afile3.wav">file 3
</SELECT>
</FORM>

<A HREF="default.wav" onClick="this.href=document.myform.myselect.options[document.myform.myselect.selectedIndex].value"><IMG SRC="apicture.gif" HEIGHT="100" WIDTH="100" BORDER="0"></A>

I prefer the second one.

©2018 Martin Webb