...

View Full Version : choosing a sound to play from a drop down box?? please help!!



cram81uk
01-31-2004, 10:13 PM
if any one can help me with this problem I would be so grateful as Ive been stuck on it for over a week now ....

basically i want the user to select a file from a drop down box and then this will then pass the file name to the player which takes in filename as one its parameters...
i know the update needs to assigned to an onChange() handler but i dont know how to access the <objects> parameters....

heres my code.. ive tried writing a function which returns the string in the drop down box but i dont know how to pass it to the the objects parameters... ...

like i mentioned b4 , im really stuck and would appreciate any help offered.....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<script language="JavaScript">
<!--

function changeFile(the_file)
{
var the_url = the file;
return the_url;

/*This is just returning a value but I
* want it to update the parameter "FileName" value
* to the item in the drop down box
*/
}
//-->
</script>
</head>
<body>

<h2>Playing The Object</h2>
<form name="the_form">
<select name="choose_file"
onChange="changeFile(window.document.the_form.choose_file.
options[selectedIndex].text);">
<option selected>loop1.wav
<option>loop2.wav
</select><BR><BR><BR>

<object height="13.5%" width="25%" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" >
<param name="AutoStart" value="1" />
<param name="FileName" value="loop1.wav" />
// How do I access this value parameter above??
</object>
</body>

<script language="JavaScript">
<!--
window.open = SymRealWinOpen;
//-->
</script>
</html>

thanks

mark

Vincent Puglia
02-01-2004, 01:24 AM
Hi,

1) give the object an id so that you can reference it
2) using the passed parameter change the value of the FileName parameter
3) change your select statement so that the first option is a 'holder' -- otherwise, the user will never be able to select the first sound without selecting something else first (since there wouldn't be a 'change')
4) close your option tags



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<script language="JavaScript">
<!--

function changeFile(the_file)
{
document.getElementById('thePlayer').FileName = the_file;
}
//-->
</script>
</head>
<body>

<h2>Playing The Object</h2>
<form name="the_form">
<select name="choose_file"
onChange="changeFile(this.options[selectedIndex].value);">
<option value="" selected>Select a Sound</option>
<option value='old\DoorOpen.wav' selected>open</option>
<option value='old\DoorClose.wav'>close</option>
</select><BR><BR><BR>

<object height="13.5%" width="25%" id='thePlayer' classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
<param name="AutoStart" value="1" />
<param name="FileName" value ='' />
</object>

</body>

</html>


Vinny

cram81uk
02-01-2004, 12:10 PM
hey thanks so much for that .... its been stressing me so much!

mark

Code Wizard
02-01-2004, 08:49 PM
Isn't there another way of playing sounds when a user clicks a link or somethin,I remember some dude from JavaScriptKit did it,and didn't use The Windows Media Player ActiveX Control,can anyone (pretty please) post the link to that ... ?

Code Wizard
02-01-2004, 08:58 PM
Oh,just found it,note that this is the cross-browser approach:
http://www.javascriptkit.com/script/script2/soundlink.shtml



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum