Jump to content

img src in document.write


phpgoal

Recommended Posts

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" 
/> ");}
 
Link to comment
Share on other sites

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='...' ...");

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.