...

View Full Version : Not quite sure what the problem is



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

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>

<div id="selected"><img id="preview-image" src="uploads/previews/2.png" alt="Two"/></div>
</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, 07:28 AM
<script type="text/javascript">
function previewimage(imagename) {
document.getElementById("preview-image").src="uploads/previews/" + imagename;
}
</script>

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

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

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

GSimpson
05-19-2009, 07: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, 08:01 AM
This may help:-

http://www.tech-evangelist.com/2008/10/05/file-paths/

GSimpson
05-19-2009, 08: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, 10:49 AM
Try:-

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

venegal
05-19-2009, 11:36 AM
This is probably a problem:

onmouseover="previewimage(2.png)"
Should be:

onmouseover="previewimage('2.png')"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum