function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kfhohnkfhohn 

simple javascript problem in visualforce

Hi-

 

I'm a beginner with visualforce, and I'm trying to implement a simple javascript image slideshow for a splash page. I implemented it successfully in standard html, but visualforce doesn't seem to like it.

 

The script to preload the images is in the head:

<script type="text/javascript">

<!--

var image1=new Image()

image1.src="{!$Resource.slide1}"

var image2=new Image()

image2.src="{!$Resource.slide2}"

var image3=new Image()

image3.src="{!$Resource.slide3}"

-->

</script>

 

Then the script for the slideshow is in the body:

 

<img src="{!$Resource.slide1}" name="slide" />

<script>

<!--

var step=1

function slideit(){

if (!document.images)

return

document.images.slide.src=eval("image"+step+".src")

if (step<3)

step++

else

step=1

setTimeout("slideit()",5000)

}

slideit()

//-->

</script>

 

Plz help, I'm totally noobing out on this one :(

 

-Karl

Best Answer chosen by Admin (Salesforce Developers) 
stephanstephan

I couple of suggestions:

 

1) Try this in Firefox and use the Firebug extension to help identify any script errors.

 

2) Get rid of the <!-- and --> HTML comments. You don't need them in a script block.

 

3) View source on the rendered page and not what you see for:

image1.src="{!$Resource.slide1}"

 

Does it contain a path the the image as you'd expect?

 

...stephan

 

 

All Answers

imuinoimuino

At first sight it all looks good, and theres no reason for salesforce to break it. Did you try to debug it? If not try doing this.

If you never debug javascript you can do it with bugzilla, a plug in for mozilla which tells you if there are errors on the script.

 

P.S: I highly recommend you to use some javascript library, jQuery is a great one and easy to use.

 

stephanstephan

I couple of suggestions:

 

1) Try this in Firefox and use the Firebug extension to help identify any script errors.

 

2) Get rid of the <!-- and --> HTML comments. You don't need them in a script block.

 

3) View source on the rendered page and not what you see for:

image1.src="{!$Resource.slide1}"

 

Does it contain a path the the image as you'd expect?

 

...stephan

 

 

This was selected as the best answer
SteveBowerSteveBower

Can you post the entire VF page, including Apex Tags?   I was curious when you said that some of the script was in the <Head> section.

kfhohnkfhohn

Looked at it with Firebug and saw that the HTML comments were overriding the scripts... got rid of the comments and everything worked like a charm.

 

Thanks all!!

 

-k