By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,649 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

erratic JS behaviour

P: n/a
Hi all, This should be a simple fix for someone.
I'm making a site that uses only one tiny bit of javascript.
It's for opening large versions of thumbnail images in the same page.
Very simple, works well but not perfectly.
The thumbnails sometimes take 2 clicks before the large image appears
correctly.
Lookit : http://www.lisavallentin.com/images.html
(please excuse that the site is half complete and lacking ie css)

the script :
<script type="text/javascript">
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('picswap').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
</script>

called like this :
<a onclick="return showPic(this)" href="images/debbie.jpg"
title="Debbie (watercolour)" ></a>

Any help would be greatly appreciated.
I'm not too hot on the js, but I'm eager to learn.

i

Dec 14 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> "osmanjaro" <os*******@gmail.com> wrote:
news:11*********************@g49g2000cwa.googlegro ups.com....

Hi all, This should be a simple fix for someone.
I'm making a site that uses only one tiny bit of javascript.
It's for opening large versions of thumbnail images in the same
page. Very simple, works well but not perfectly.
The thumbnails sometimes take 2 clicks before the large image
appears correctly.
Lookit : http://www.lisavallentin.com/images.html
(please excuse that the site is half complete and lacking ie css)

the script :
<script type="text/javascript">
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('picswap').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
</script>

called like this :
<a onclick="return showPic(this)" href="images/debbie.jpg"
title="Debbie (watercolour)" ></a>

Any help would be greatly appreciated.
I'm not too hot on the js, but I'm eager to learn.


<script type="text/javascript">
function showPic (whichpic) {
var a=(document.getElementById)?false:true;
if (document.getElementById) {
document.getElementById('picswap').src = whichpic.href;
document.getElementById('desc').childNodes[0].nodeValue=
(whichpic.title)?whichpic.title:whichpic.childNode s[0].nodeValue;
}
return a;
}
function correction(){
document.getElementById('picswap').style.display=' none';
document.getElementById('picswap').style.display=' ';
}
</script>

<img id="picswap" src="images/bit.gif" alt="" onload="correction()" />

--
BootNic Thursday, December 15, 2005 9:21 PM

A well-developed sense of humor is the pole that adds balance to your step as you walk the tightrope of life
*William Arthur Ward*

Dec 16 '05 #2

P: n/a
> BootNic Thursday, December 15, 2005 9:21 PM wrote back

Much obliged BootNic.

i

Dec 16 '05 #3

P: n/a
In article <Rw**************@newssvr17.news.prodigy.com>,
"BootNic" <Bo*****@bounce.prodigy.net> wrote:
<script type="text/javascript">
function showPic (whichpic) {
var a=(document.getElementById)?false:true;
if (document.getElementById) {
document.getElementById('picswap').src = whichpic.href;
document.getElementById('desc').childNodes[0].nodeValue=
(whichpic.title)?whichpic.title:whichpic.childNode s[0].nodeValue;
}
return a;
}
function correction(){
document.getElementById('picswap').style.display=' none';
document.getElementById('picswap').style.display=' ';
}
</script>

<img id="picswap" src="images/bit.gif" alt="" onload="correction()" />

--
BootNic Thursday, December 15, 2005 9:21 PM


site:
http://www.lisavallentin.com/sketches.html

Hi,
I did use this amended code in the .js file and xhtml.
The onload="correction()" part in the link does not validate and the
image loading problem (takes a double click to bring the image to the
front) still persists. I going back to my original flawed method.

Is there a way to do this all in the .js file and not in the html.
It should be possible to get the javascript to only be applied to links
class="showme" for example.

Strange that onclick="" would validate xhtml and onload="" doesn't.

--
i
Dec 21 '05 #4

P: n/a
> "I Osman" <os*****@dircon.co.uk> wrote:
news:os***************************@news.ndo.com... .

In article <Rw**************@newssvr17.news.prodigy.com>,
"BootNic" <Bo*****@bounce.prodigy.net> wrote:
<script type="text/javascript">
function showPic (whichpic) {
var a=(document.getElementById)?false:true;
if (document.getElementById) {
document.getElementById('picswap').src = whichpic.href;
document.getElementById('desc').childNodes[0].nodeValue=
(whichpic.title)?whichpic.title:whichpic.childNode s[0].nodeValue;
}
return a;
}
function correction(){
document.getElementById('picswap').style.display=' none';
document.getElementById('picswap').style.display=' ';
}
</script>

<img id="picswap" src="images/bit.gif" alt=""
onload="correction()" />


site:
http://www.lisavallentin.com/sketches.html

Hi,
I did use this amended code in the .js file and xhtml.
The onload="correction()" part in the link does not validate and the
image loading problem (takes a double click to bring the image to
the front) still persists. I going back to my original flawed
method.

Is there a way to do this all in the .js file and not in the html.
It should be possible to get the javascript to only be applied to
links class="showme" for example.

Strange that onclick="" would validate xhtml and onload="" doesn't.


The onload="correction()" is the part that redraws the node to
correct the display issue Mozilla has, you should get the same result
with one click if you Minimize and Maximize the browser.

The showPic function did the same thing, just wrote different.

Try this in your script.js and see if it will do what you want.

function showPic (whichpic) {
var a=(document.getElementById)?false:true;
var b = whichpic.href.split('/');
if (document.getElementById) {
document.getElementById('picswap').src = whichpic.href;
document.getElementById('desc').childNodes[0].nodeValue=
(whichpic.title)?whichpic.title:b[b.length-1];
}
return a;
}
function correction(){
document.getElementById('picswap').style.display=' none';
document.getElementById('picswap').style.display=' ';
}
function loadcorrection(){
if(window.addEventListener && document.getElementById('picswap')){
document.getElementById('picswap').addEventListene r("load", correction, false);
}
}
if(window.addEventListener){
window.addEventListener("load", loadcorrection, false);
}

--
BootNic Wednesday, December 21, 2005 11:20 AM

You can discover what your enemy fears most by observing the means he uses to frighten you.
*Eric Hoffer*
Dec 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.