Hi,
I wrote a little bit of script that loads an image from a thumbnail when the
thumbnail is clicked.
It is not very clever, and I have found it only works in IE..
could someone have a look at the script below and suggest how I can make it
work in netscape too?
Steve
PS: very new to js!!
<script language="JavaScript">
var imagePos = -1;
var imageStr = "<?=writeImageArray() ?>"; //Assume this is loaded with a
string of image names separated by |
var imageArray = imageStr.split("|");
function loadPreviousImage(){
imagePos--;
if (imagePos < 0){
imagePos = imageArray.length -1;
}
loadImage(imagePos);
}
function loadNextImage(){
imagePos++;
if( imagePos >= imageArray.length){
imagePos = 0;
}
loadImage(imagePos);
}
function loadImage(i){
document.all("IMAGEHOLDER").style.visibility = "hidden";
if( imageArray.length==0){
return;
}
imagePos = i;
var imagePath = imageArray[i].split("^")[0];
var imageAlt = imageArray[i].split("^")[1];
var imageW = imageArray[i].split("^")[2];
var imageH = imageArray[i].split("^")[3];
document.all("IMAGEHOLDER").src = imagePath;
document.all("IMAGEHOLDER").alt = imageAlt;
document.all("IMAGEHOLDER").width = imageW;
document.all("IMAGEHOLDER").height = imageH;
document.all("IMAGEHOLDER").style.visibility = "visible";
document.all("CAPTION").firstChild.nodeValue = imageAlt;
}
</script> 6 1922
SPG wrote: Hi,
I wrote a little bit of script that loads an image from a thumbnail when the thumbnail is clicked. It is not very clever, and I have found it only works in IE..
could someone have a look at the script below and suggest how I can make it work in netscape too?
Stop writing IE proprietary code would be a start.
Steve
PS: very new to js!!
<script language="JavaScript"> var imagePos = -1; var imageStr = "<?=writeImageArray() ?>"; //Assume this is loaded with a string of image names separated by |
ummm, ok.
Instead of having the browser split it, why not have PHP generate the
appropriate JS code?
var imageArray = imageStr.split("|");
function loadPreviousImage(){ imagePos--; if (imagePos < 0){ imagePos = imageArray.length -1; } loadImage(imagePos); } function loadNextImage(){ imagePos++; if( imagePos >= imageArray.length){ imagePos = 0; } loadImage(imagePos); } function loadImage(i){ document.all("IMAGEHOLDER").style.visibility = "hidden";
document.all is an MSIE only (within limits) code practice.
document.images['IMAGEHOLDER'].style.visibility = "hidden";
assuming you have the style attribute on an img tag with name="IMAGEHOLDER"
if( imageArray.length==0){ return; } imagePos = i; var imagePath = imageArray[i].split("^")[0]; var imageAlt = imageArray[i].split("^")[1]; var imageW = imageArray[i].split("^")[2]; var imageH = imageArray[i].split("^")[3]; document.all("IMAGEHOLDER").src = imagePath;
document.images['IMAGEHOLDER'].src = imgPath
document.all("IMAGEHOLDER").alt = imageAlt;
document.images['IMAGEHOLDER'].alt=imageAlt;
document.all("IMAGEHOLDER").width = imageW;
document.images['IMAGEHOLDER'].width=imageW;
document.all("IMAGEHOLDER").height = imageH;
document.images['IMAGEHOLDER'].height = imageH;
document.all("IMAGEHOLDER").style.visibility = "visible";
document.images['IMAGEHOLDER'].style.visibility = "visible";
document.all("CAPTION").firstChild.nodeValue = imageAlt;
document.getElementByID('CAPTION').firstChild.node VAlue = imagAlt;
Assuming you have something like:
<div id="CAPTION">..</div>
} </script>
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Hi Randy,
Thanks for this...
All seems to work fine except for
"Randy Webb" <Hi************@aol.com> wrote in message
news:l6********************@comcast.com... SPG wrote:
Hi,
I wrote a little bit of script that loads an image from a thumbnail when the thumbnail is clicked. It is not very clever, and I have found it only works in IE..
could someone have a look at the script below and suggest how I can make it work in netscape too?
Stop writing IE proprietary code would be a start.
Steve
PS: very new to js!!
<script language="JavaScript"> var imagePos = -1; var imageStr = "<?=writeImageArray() ?>"; //Assume this is loaded with a string of image names separated by |
ummm, ok. Instead of having the browser split it, why not have PHP generate the appropriate JS code?
var imageArray = imageStr.split("|");
function loadPreviousImage(){ imagePos--; if (imagePos < 0){ imagePos = imageArray.length -1; } loadImage(imagePos); } function loadNextImage(){ imagePos++; if( imagePos >= imageArray.length){ imagePos = 0; } loadImage(imagePos); } function loadImage(i){ document.all("IMAGEHOLDER").style.visibility = "hidden";
document.all is an MSIE only (within limits) code practice.
document.images['IMAGEHOLDER'].style.visibility = "hidden";
assuming you have the style attribute on an img tag with name="IMAGEHOLDER"
if( imageArray.length==0){ return; } imagePos = i; var imagePath = imageArray[i].split("^")[0]; var imageAlt = imageArray[i].split("^")[1]; var imageW = imageArray[i].split("^")[2]; var imageH = imageArray[i].split("^")[3]; document.all("IMAGEHOLDER").src = imagePath;
document.images['IMAGEHOLDER'].src = imgPath
document.all("IMAGEHOLDER").alt = imageAlt;
document.images['IMAGEHOLDER'].alt=imageAlt;
document.all("IMAGEHOLDER").width = imageW;
document.images['IMAGEHOLDER'].width=imageW;
document.all("IMAGEHOLDER").height = imageH;
document.images['IMAGEHOLDER'].height = imageH;
document.all("IMAGEHOLDER").style.visibility = "visible";
document.images['IMAGEHOLDER'].style.visibility = "visible";
document.all("CAPTION").firstChild.nodeValue = imageAlt;
document.getElementByID('CAPTION').firstChild.node VAlue = imagAlt;
Assuming you have something like: <div id="CAPTION">..</div>
} </script>
-- Randy comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly Answer:It destroys the order of the conversation Question: Why? Answer: Top-Posting. Question: Whats the most annoying thing on Usenet?
Hi Randy,
Thanks for this, All seems to work fine except for this...
document.getElementByID('CAPTION').firstChild.node Value = imagAlt;
The "CAPTION" element is buried inside a teble cell like so..
.....some html....
<td colspan=2 ID="CAPTION_CELL"><DIV ID="CAPTION"> <DIV></td>
....some more!...
Not a show stopper if I cannot make that bit work, but would be nice!
Steve
"Randy Webb" <Hi************@aol.com> wrote in message
news:l6********************@comcast.com... SPG wrote:
Hi,
I wrote a little bit of script that loads an image from a thumbnail when the thumbnail is clicked. It is not very clever, and I have found it only works in IE..
could someone have a look at the script below and suggest how I can make it work in netscape too?
Stop writing IE proprietary code would be a start.
Steve
PS: very new to js!!
<script language="JavaScript"> var imagePos = -1; var imageStr = "<?=writeImageArray() ?>"; //Assume this is loaded with a string of image names separated by |
ummm, ok. Instead of having the browser split it, why not have PHP generate the appropriate JS code?
var imageArray = imageStr.split("|");
function loadPreviousImage(){ imagePos--; if (imagePos < 0){ imagePos = imageArray.length -1; } loadImage(imagePos); } function loadNextImage(){ imagePos++; if( imagePos >= imageArray.length){ imagePos = 0; } loadImage(imagePos); } function loadImage(i){ document.all("IMAGEHOLDER").style.visibility = "hidden";
document.all is an MSIE only (within limits) code practice.
document.images['IMAGEHOLDER'].style.visibility = "hidden";
assuming you have the style attribute on an img tag with name="IMAGEHOLDER"
if( imageArray.length==0){ return; } imagePos = i; var imagePath = imageArray[i].split("^")[0]; var imageAlt = imageArray[i].split("^")[1]; var imageW = imageArray[i].split("^")[2]; var imageH = imageArray[i].split("^")[3]; document.all("IMAGEHOLDER").src = imagePath;
document.images['IMAGEHOLDER'].src = imgPath
document.all("IMAGEHOLDER").alt = imageAlt;
document.images['IMAGEHOLDER'].alt=imageAlt;
document.all("IMAGEHOLDER").width = imageW;
document.images['IMAGEHOLDER'].width=imageW;
document.all("IMAGEHOLDER").height = imageH;
document.images['IMAGEHOLDER'].height = imageH;
document.all("IMAGEHOLDER").style.visibility = "visible";
document.images['IMAGEHOLDER'].style.visibility = "visible";
document.all("CAPTION").firstChild.nodeValue = imageAlt;
document.getElementByID('CAPTION').firstChild.node VAlue = imagAlt;
Assuming you have something like: <div id="CAPTION">..</div>
} </script>
-- Randy comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly Answer:It destroys the order of the conversation Question: Why? Answer: Top-Posting. Question: Whats the most annoying thing on Usenet?
SPG wrote: Hi Randy,
Thanks for this, All seems to work fine except for this...
document.getElementByID('CAPTION').firstChild.node Value = imagAlt;
The "CAPTION" element is buried inside a teble cell like so..
.....some html.... <td colspan=2 ID="CAPTION_CELL"><DIV ID="CAPTION"> <DIV></td> ....some more!...
Not a show stopper if I cannot make that bit work, but would be nice!
document.getElementByID('CAPTION').innerHTML = imageAlt;
But it should have complained that imagAlt was undefined since I made a
typo in replying to you. Read the Group FAQ, DynWrite specifically, on
changing the contents of a DIV tag. Also read my signature (along with
the FAQ) with regards to top-posting.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
"Randy Webb" <Hi************@aol.com> wrote in message
news:O-********************@comcast.com... SPG wrote: Hi Randy,
Thanks for this, All seems to work fine except for this...
document.getElementByID('CAPTION').firstChild.node Value = imagAlt;
The "CAPTION" element is buried inside a teble cell like so..
.....some html.... <td colspan=2 ID="CAPTION_CELL"><DIV ID="CAPTION"> <DIV></td> ....some more!...
Not a show stopper if I cannot make that bit work, but would be nice!
document.getElementByID('CAPTION').innerHTML = imageAlt;
But it should have complained that imagAlt was undefined since I made a typo in replying to you. Read the Group FAQ, DynWrite specifically, on changing the contents of a DIV tag. Also read my signature (along with the FAQ) with regards to top-posting.
-- Randy comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly Answer:It destroys the order of the conversation Question: Why? Answer: Top-Posting. Question: Whats the most annoying thing on Usenet?
Hi Randy
Thanks for that.. it works of course. (I managed the typo myself previously)
As for top-posting.. My apologies. Wrists are slapped!
Thanks for the help!
Steve
SPG wrote:
[...] } function loadImage(i){ document.all("IMAGEHOLDER").style.visibility = "hidden"; if( imageArray.length==0){ return; } imagePos = i;
Without prejudice to anything Randy posted, I think the
following can be tidied up thusly:
var imagePath = imageArray[i].split("^")[0]; var imageAlt = imageArray[i].split("^")[1]; var imageW = imageArray[i].split("^")[2]; var imageH = imageArray[i].split("^")[3]; document.all("IMAGEHOLDER").src = imagePath; document.all("IMAGEHOLDER").alt = imageAlt; document.all("IMAGEHOLDER").width = imageW; document.all("IMAGEHOLDER").height = imageH; document.all("IMAGEHOLDER").style.visibility = "visible";
var imgA = imageArray[i].split("^");
var iHolder = document.images['IMAGEHOLDER'];
iHolder.src = imgA[0];
iHolder.alt = imgA[1];
iHolder.width = imgA[2];
iHolder.height = imgA[3];
iHolder.style.visibility = "visible";
That's gotta save a few clock cycles...
--
Fred This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Henning Vestergaard Poulsen |
last post by:
Hi, I have a problem that I hope someone can help me with.
I'm building a web page with pictures I've taken with my digital camera. I
have succeded making a javacript that, when clicking on a...
|
by: antishok |
last post by:
Hi,
I'm writing a page which has a somewhat similar folder tree to that of
the windows explorer, where each folder is made of a <SPAN> tag
consisting of the folder image (closed or open) and the...
|
by: C A Upsdell |
last post by:
I have a site where I am setting a style dynamically, using the JS
statement:
obj.style.backgroundImage = 'url(img/bak_page.jpg)';
where 'obj' is either document.getElementById(id), or...
|
by: Nicholas Couch |
last post by:
I have a little form with a couple of dynamically generated list
boxes. When the user makes a selection from the first box, the second
box is refreshed. When they make a selection from the second...
|
by: Thomas |
last post by:
Hi,
I'm having a problem with the dynamically created inputfields in
Internet Explorer.
The situation is the following:
- I have a dynamically created table with a textbox in each Cell.
- It...
| |
by: Donald Xie |
last post by:
Hi,
I noticed an interesting effect when working with controls that are
dynamically loaded. For instance, on a web form with a PlaceHolder control
named ImageHolder, I dynamically add an image...
|
by: max |
last post by:
Hello,
Based on various posts, I've come up with the following code to load
data into a js array dynamically without a screen refresh. It works,
but you have to push the button twice before it...
|
by: GaryB |
last post by:
Hi Guys,
I've been battling with this one for hours - I hope that you can help
me!
My code modifies the <aon a page, from a standard document link into
a link with a tailored onclick event.
...
|
by: miladhatam |
last post by:
can i change the size of a file dynamically ?
for example have 100 Kb and i want to decrease it to 20 Kb
thanks
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |
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,...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |