View Full Version : Not quite sure what the problem is

05-19-2009, 08:22 AM
<script language="javascript" type="text/javascript">
function previewimage(imagename) {
document.getElementById("preview-image").src="uploads/previews/" . imagename;

Hi there. I have this piece of coding sitting in the head coding of my website. I'm unsure of any syntax errors in it, but I do know that it's not working when called upon like this:

<div id="recent-rotator">

<div id="selection">
<a href="entry/?id=2" onmouseover="previewimage(2.png)">Two</a>
<a href="entry/?id=1" onmouseover="previewimage(1.png)">One</a>

<div id="selected"><img id="preview-image" src="uploads/previews/2.png" alt="Two"/></div>

I honestly, cannot figure out what's wrong with it. I bet that it's something simple. I've checked directories etc and they are fine, but I can't work out why it won't change image upon mouse over. I don't use Javascript a lot so any help would be nice.

Thank you :)

Philip M
05-19-2009, 08:28 AM
<script type="text/javascript">
function previewimage(imagename) {
document.getElementById("preview-image").src="uploads/previews/" + imagename;

Tourist in hotel in Jasper, Canada: "Do we need to convert our Canadian currency into British pounds when we go on to British Columbia?"

05-19-2009, 08:30 AM
Thank you. ^_^

I've forgotten the basics of javascript - Too much PHP. :o

05-19-2009, 08:38 AM
Hmmm still not working, is it possible, that there is something else that could be stopping it from changing?

Philip M
05-19-2009, 09:01 AM
This may help:-


05-19-2009, 09:52 AM
I experiemented with the script, and I've put it down to javascript syntax when calling on the variable from the function parameters - is there a better way to write this?

Philip M
05-19-2009, 11:49 AM

src='"uploads/previews/" + imagename';

05-19-2009, 12:36 PM
This is probably a problem:

Should be: