By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Text to Speech Javascript

P: 23
Why do my images dissappear after I clik on them? Otherwise, the text to speech is working just fine. However, it is not functional if the images dissappear.

[HTML]<script language="JavaScript" type="text/javascript" >
<!--

function insertTTS(tts,loop) {
document.write('<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0" ID=ib_tts width=1 height=1>\n');
document.write('<param name=src value="media/tts.dcr">\n');
document.write('<param name=swRemote value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\' ">\n');
document.write('<param name=swStretchStyle value=none>\n');
document.write('<param name="sw9" value="'+tts+'">\n');
document.write('<param name="sw8" value="'+loop+'">\n');
document.write('<embed src="media/tts.dcr" bgColor=#FFFFFF width=1 height=1 swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\' " swStretchStyle=none type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/" sw9="'+tts+'" sw8="'+loop+'"></embed>\n');
document.write('</object>\n');
}
//-->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

</head>
<p><img src="dog.jpg" width="50" height="66" onclick="insertTTS('My favorite animals', 'false')" /></p>
<p><img src="dog.jpg" width="50" height="66" onclick="insertTTS('My favorite martian', 'false')" /></p>

<p>&nbsp;</p>
</body>
</html>[/HTML]
Nov 20 '07 #1
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
You can't use document.write after the page has loaded.

Either create the objects and append them to the body or set the innerHTML property of a div element within the page.
Nov 20 '07 #2

P: 23
What would the div element look like? Sorry, I'm a beginner.


You can't use document.write after the page has loaded.

Either create the objects and append them to the body or set the innerHTML property of a div element within the page.
Nov 20 '07 #3

acoder
Expert Mod 15k+
P: 16,027
What would the div element look like? Sorry, I'm a beginner.
It doesn't necessarily have to be a div. You could even use the <p> tag that you already have.

Give the element an id:
[HTML]<div id="content"></div>[/HTML]

In your function, access the element:
Expand|Select|Wrap|Line Numbers
  1. var div = document.getElementById("content");
Also convert the document.write statements into a string and then set div.innerHTML to that string.

One final thing: you have an opening body tag missing.
Nov 20 '07 #4

P: 23
Would you mind showing me how this would look in my code. I hate to take up your time but what I've tried isn't working.
Thanks!

It doesn't necessarily have to be a div. You could even use the <p> tag that you already have.

Give the element an id:
[HTML]<div id="content"></div>[/HTML]

In your function, access the element:
Expand|Select|Wrap|Line Numbers
  1. var div = document.getElementById("content");
Also convert the document.write statements into a string and then set div.innerHTML to that string.

One final thing: you have an opening body tag missing.
Nov 21 '07 #5

acoder
Expert Mod 15k+
P: 16,027
To get you started:
Expand|Select|Wrap|Line Numbers
  1. function insertTTS(tts,loop) {
  2.     var str = '<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0" ID=ib_tts width=1 height=1>';
  3.     str += '<param name=src value="media/tts.dcr">';
  4.     str += '<param name=swRemote value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\' ">';
  5.     // and likewise for the rest of the document.write statements.
  6.     document.getElementById("content").innerHTML = str;
  7. }
If you can't get it to work, post your code.
Nov 21 '07 #6

P: 23
Thank you for helping a beginner!
Nov 21 '07 #7

acoder
Expert Mod 15k+
P: 16,027
No problem, glad you got it working.
Nov 22 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.