phpgoal Posted June 13, 2013 Share Posted June 13, 2013 Hello, I have the below code. When myFunction is called, I want to see the slide show start but it does not. Document.write is correct? Please help. <script type="text/javascript"> if (datestr == 'September 2020') {var image1=new Image() image1.src="car1.jpg" var image2=new Image() image2.src="car3.jpg" myFunction(datestr); } function myFunction(a) { document.getElementById("demo").innerHTML=a; document.write("<img src="car1.jpg" name="slide" width="435" height="500" /> "); } </script> if (datestr == 'September 2020') {var image1=new Image() image1.src="car1.jpg" var image2=new Image() image2.src="car3.jpg"myFunction(datestr); } function myFunction(a){document.getElementById("demo").innerHTML=a; document.write("<img src="car1.jpg" name="slide" width="435" height="500" /> ");} Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/ Share on other sites More sharing options...
Irate Posted June 13, 2013 Share Posted June 13, 2013 You are ending your document.write too early. document.write("<img src=" /* here your parsing stops the document.write method */ ... Use single quotes for the img src or escape them with a backslash. document.write("<img src=\"...\" ...") || document.write("<img src='...' ..."); Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1435780 Share on other sites More sharing options...
phpgoal Posted June 13, 2013 Author Share Posted June 13, 2013 Before my code was failing. Now below code passes. But the problem is slideshow does now start. It is stuck at car1 picture. document.write("<img src=\"car1.jpg\" name=\"slide\" /> "); Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1435791 Share on other sites More sharing options...
Irate Posted June 13, 2013 Share Posted June 13, 2013 What's the code for the slideshow? The code you provided above does not really look like it loops through anything. Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1435801 Share on other sites More sharing options...
phpgoal Posted June 13, 2013 Author Share Posted June 13, 2013 I have tested in html it works. Not in JS. works if i do in html as below: <tr> <td colspan=6 align='center' ><img src="cars1.jpg" name="slide" width="435" height="500" /></td></tr> Does not work if i write in JS as below: document.write("<img src=\"car1.jpg\" name=\"slide\" /> "); Below does the slide: <script> <!-- //variable that will increment through the images var step=1 function slideit(){ //if browser does not support the image object, exit. if (!document.images) return document.images.slide.src=eval("image"+step+".src") if (step<2) step++ else step=1 //call function "slideit()" every 2.5 seconds setTimeout("slideit()",2500) } slideit() //--> </script> Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1435815 Share on other sites More sharing options...
cyberRobot Posted June 14, 2013 Share Posted June 14, 2013 Does not work if i write in JS as below: document.write("<img src=\"car1.jpg\" name=\"slide\" /> "); Try removing the line break. document.write("<img src=\"car1.jpg\" name=\"slide\" /> "); Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1435946 Share on other sites More sharing options...
phpgoal Posted June 14, 2013 Author Share Posted June 14, 2013 Your code is same as mine. Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1435952 Share on other sites More sharing options...
cyberRobot Posted June 18, 2013 Share Posted June 18, 2013 Ah, the function is being called before the page is fully loaded. Try changing the initial call to window.onload = slideit; Quote Link to comment https://forums.phpfreaks.com/topic/279121-img-src-in-documentwrite/#findComment-1436595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.