473,387 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

erratic JS behaviour

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
4 1375
> "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
> BootNic Thursday, December 15, 2005 9:21 PM wrote back

Much obliged BootNic.

i

Dec 16 '05 #3
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
> "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: One's Too Many | last post by:
Ran into a strange problem today: 8.1.7 on AIX 4.3.3 Database and applications had been working fine for two years and all of a sudden a couple of regularly-run queries are now no longer...
2
by: Mike | last post by:
I have a typical two frame frameset. Menu frame on the left, load content on the right frame. Lately I have been having problems in that sometimes menu links will open a new window instead of...
2
by: Joona I Palaste | last post by:
AFAIK the C standard divides behaviour of different things into four classes. 1) Defined behaviour. The implementation must do exactly what the standard says. 2) Implementation-defined behaviour....
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
0
by: Dennis | last post by:
I thought some might be interested in an erratic error that I finally found in my program: I had a class that opened a filestream for a file which I inadvertently forgot to close after it was...
2
by: Rico | last post by:
Hello, I have Visual Studio 2003, working on a VB.net project. When I try to step through the code, the behavior is erratic, stepping in places where no code exists, jumping over code sections...
26
by: Frederick Gotham | last post by:
I have a general idea of the different kinds of behaviour described by the C Standard, such as: (1) Well-defined behaviour: int a = 2, b = 3; int c = a + b; (Jist: The code will work...
0
by: janefield2002 | last post by:
Hi there, I get the following error using Access ODBC drivers: '(unknown)' is not a valid path. make sure that the path name is spelled correctly and you are connected to the server on which...
0
by: janefield2002 | last post by:
Hi there, I get the following error using Access ODBC drivers: Microsoft OLE DB Provider for ODBC Drivers error '80004005' '(unknown)' is not a valid path. Make sure that the path name is...
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.