473,762 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cobbling functions together

Hello.

I have a problem trying to get seperate image functions to work
together.

Starting with the img tag and associated html:

<img src="image1.jpg " NAME="theImage" pbsrc="image1_l rg.jpg"
style="width: 125px; height: 125px;" class="PopBoxIm ageSmall"
onclick="Pop(th is,50,'PopBoxIm ageLarge');" ondblclick="Rev ert
(this,50,'PopBo xImageSmall');" />
<input type="button" value="&lt;&lt; Previous" name="previous"
onClick="Backer ()"></td>
<td align="center"> <input type="button" value="Next &gt;&gt;"
name="next" onClick="Nexter ()">
The above buttons Next and Previous run two functions called Nexter and
Backer which swap theImage source of a small image. That works fine.
The javascript for that is at the bottom of this post.

Now, please notice that within the img tag is this:

pbsrc="image1_l rg.jpg"

that is used to run the two functions Pop() and Revert() in the img tag
which magnifys and then reduces the image by swapping in a larger
version of the same image (using a fancy inline css magnification zoom
type thing). In this case as written it calls "image1_lrg.jpg " which is
the large counterpart to "image1.jpg "

The javascript that runs the magnification is very large and complicated
and beyond my understanding except that I know whatever is set as
"pbsrc" is what gets magnified.

The problem is, whenever the functions Nexter and Backer are called to
swap the small images, I need to change the pbsrc to the corresponding
"_lrg.jpg" image path that can get passed to the javascript that runs
the magnification.

As it stands now, pbsrc always remains "image1_lrg.jpg " even as the
images are swapped using nexter and backer.

If you look in the script for Nexter and Backer just below, the small
image swap array is pretty clear.

So, when theImage.src gets changed to 'image2.jpg" the pbsrc has to get
changed to "image2_lrg.jpg " and so on.

Is there some way to change the value of pbsrc in the img tag as needed,
each time Nexter and Backer are called?

Thank you very much.

<script language="JavaS cript">
currentIndx=0;
MyImages=new Array();
MyImages[0]='image1.jpg';
MyImages[1]='image2.jpg';
MyImages[2]='image3.jpg';
MyImages[3]='image4.jpg';

imagesPreloaded = new Array(4)
for (var i = 0; i < MyImages.length ; i++)
{
imagesPreloaded[i] = new Image()
imagesPreloaded[i].src=MyImages[i]
}
function Nexter(){
if (currentIndx<im agesPreloaded.l ength-1){
currentIndx=cur rentIndx+1;
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
else {
currentIndx=0
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
}

function Backer(){
if (currentIndx>0) {
currentIndx=cur rentIndx-1;
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
else {
currentIndx=6
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}}
Jul 9 '08 #1
5 1178
Can anyone help? I know the post is kind of long, I wanted to explain
thoroughly enough. I think it comes down to passing variables, but I am
not sure.

Thanks again.
James <Ja*********@th anks.comwrote in
news:Xn******** *************** ***@216.196.97. 136:
Hello.

I have a problem trying to get seperate image functions to work
together.

Starting with the img tag and associated html:

<img src="image1.jpg " NAME="theImage" pbsrc="image1_l rg.jpg"
style="width: 125px; height: 125px;" class="PopBoxIm ageSmall"
onclick="Pop(th is,50,'PopBoxIm ageLarge');" ondblclick="Rev ert
(this,50,'PopBo xImageSmall');" />
<input type="button" value="&lt;&lt; Previous" name="previous"
onClick="Backer ()"></td>
<td align="center"> <input type="button" value="Next &gt;&gt;"
name="next" onClick="Nexter ()">
The above buttons Next and Previous run two functions called Nexter
and
Backer which swap theImage source of a small image. That works fine.
The javascript for that is at the bottom of this post.

Now, please notice that within the img tag is this:

pbsrc="image1_l rg.jpg"

that is used to run the two functions Pop() and Revert() in the img
tag
which magnifys and then reduces the image by swapping in a larger
version of the same image (using a fancy inline css magnification zoom
type thing). In this case as written it calls "image1_lrg.jpg " which
is
the large counterpart to "image1.jpg "

The javascript that runs the magnification is very large and
complicated
and beyond my understanding except that I know whatever is set as
"pbsrc" is what gets magnified.

The problem is, whenever the functions Nexter and Backer are called to
swap the small images, I need to change the pbsrc to the corresponding
"_lrg.jpg" image path that can get passed to the javascript that runs
the magnification.

As it stands now, pbsrc always remains "image1_lrg.jpg " even as the
images are swapped using nexter and backer.

If you look in the script for Nexter and Backer just below, the small
image swap array is pretty clear.

So, when theImage.src gets changed to 'image2.jpg" the pbsrc has to
get
changed to "image2_lrg.jpg " and so on.

Is there some way to change the value of pbsrc in the img tag as
needed,
each time Nexter and Backer are called?

Thank you very much.

<script language="JavaS cript">
currentIndx=0;
MyImages=new Array();
MyImages[0]='image1.jpg';
MyImages[1]='image2.jpg';
MyImages[2]='image3.jpg';
MyImages[3]='image4.jpg';

imagesPreloaded = new Array(4)
for (var i = 0; i < MyImages.length ; i++)
{
imagesPreloaded[i] = new Image()
imagesPreloaded[i].src=MyImages[i]
}
function Nexter(){
if (currentIndx<im agesPreloaded.l ength-1){
currentIndx=cur rentIndx+1;
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
else {
currentIndx=0
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
}

function Backer(){
if (currentIndx>0) {
currentIndx=cur rentIndx-1;
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
else {
currentIndx=6
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}}
Jul 11 '08 #2
James wrote:
Hello.

I have a problem trying to get seperate image functions to work
together.

Starting with the img tag and associated html:

<img src="image1.jpg " NAME="theImage" pbsrc="image1_l rg.jpg"
style="width: 125px; height: 125px;" class="PopBoxIm ageSmall"
onclick="Pop(th is,50,'PopBoxIm ageLarge');" ondblclick="Rev ert
(this,50,'PopBo xImageSmall');" />
<input type="button" value="&lt;&lt; Previous" name="previous"
onClick="Backer ()"></td>
<td align="center"> <input type="button" value="Next &gt;&gt;"
name="next" onClick="Nexter ()">
The above buttons Next and Previous run two functions called Nexter and
Backer which swap theImage source of a small image. That works fine.
The javascript for that is at the bottom of this post.

Now, please notice that within the img tag is this:

pbsrc="image1_l rg.jpg"

that is used to run the two functions Pop() and Revert() in the img tag
which magnifys and then reduces the image by swapping in a larger
version of the same image (using a fancy inline css magnification zoom
type thing). In this case as written it calls "image1_lrg.jpg " which is
the large counterpart to "image1.jpg "

The javascript that runs the magnification is very large and complicated
and beyond my understanding except that I know whatever is set as
"pbsrc" is what gets magnified.

The problem is, whenever the functions Nexter and Backer are called to
swap the small images, I need to change the pbsrc to the corresponding
"_lrg.jpg" image path that can get passed to the javascript that runs
the magnification.

As it stands now, pbsrc always remains "image1_lrg.jpg " even as the
images are swapped using nexter and backer.

If you look in the script for Nexter and Backer just below, the small
image swap array is pretty clear.

So, when theImage.src gets changed to 'image2.jpg" the pbsrc has to get
changed to "image2_lrg.jpg " and so on.

Is there some way to change the value of pbsrc in the img tag as needed,
each time Nexter and Backer are called?
Just set it to an appropriate value.

<script language="JavaS cript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

currentIndx=0;
All variables should be declared with var:

var currentIndx=0;

MyImages=new Array();
MyImages[0]='image1.jpg';
MyImages[1]='image2.jpg';
MyImages[2]='image3.jpg';
MyImages[3]='image4.jpg';
By convention, variable names starting with a capital letter are
reserved for constructors. Also, consider using an array literal:

var myImages = ['image1.jpg', 'image2.jpg',
'image3.jpg', 'image4.jpg'];

imagesPreloaded = new Array(4)
There is no need to specify a length when creating a new array, an array
literal can be used here too:

var imagesPreloaded = [];

for (var i = 0; i < MyImages.length ; i++)
{
imagesPreloaded[i] = new Image()
imagesPreloaded[i].src=MyImages[i]
}
function Nexter(){
You could replace from here...
if (currentIndx<im agesPreloaded.l ength-1){
currentIndx=cur rentIndx+1;
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
else {
currentIndx=0
document.theIma ge.src=imagesPr eloaded[currentIndx].src
}
to here with something like:

currentIndex = ++currentIndex % imagesPreloaded .length;
document.theIma ge.src = myImages[currentIndx];
Now you need to set the new value for the img element's pbsrc property,
the function might look like:

function nexter() {
currentIndex = ++currentIndex % imagesPreloaded .length;
var img = document.theIma ge;
var src = myImages[currentIndex];

img.src = src;
img.pbsrc = src.replace(/\.jpg$/, '_lrg.jpg');
}
Do a similar thing to backer(), setting the currentIndex will need to be
something like:

currentIndex = currentIndex? --currentIndex || --myImages.length ;
--
Rob
Jul 11 '08 #3
Thanks for trying, but this doesn't seem to work.

This:

function nexter() {
currentIndex = ++currentIndex % imagesPreloaded .length;
var img = document.theIma ge;
var src = myImages[currentIndex];

img.src = src;
img.pbsrc = src.replace(/\.jpg$/, '_lrg.jpg');
}

does not change the pbsrc image. It always stays the same as what it is
originally set to in the img tag:

<img src="image1.jpg " NAME="theImage" pbsrc="image1_l rg.jpg"
style="width: 125px; height: 125px;" class="PopBoxIm ageSmall"
onclick="Pop(th is,50,'PopBoxIm ageLarge');" ondblclick="Rev ert
(this,50,'PopBo xImageSmall');" />

So, no matter what nexter changes the small image to, the large image
called by pbsrc is always "image1_lrg.jpg "

Unless I am mistaken, the src attribute of an image can be changed in
this way. But pbsrc isn't an actual img attribute and cannot.

Am I mistaken?

>
Just set it to an appropriate value.

><script language="JavaS cript">

The language attribute is deprecated, type is required:

<script type="text/javascript">

>currentIndx= 0;

All variables should be declared with var:

var currentIndx=0;

>MyImages=new Array();
MyImages[0]='image1.jpg';
MyImages[1]='image2.jpg';
MyImages[2]='image3.jpg';
MyImages[3]='image4.jpg';

By convention, variable names starting with a capital letter are
reserved for constructors. Also, consider using an array literal:

var myImages = ['image1.jpg', 'image2.jpg',
'image3.jpg', 'image4.jpg'];

>imagesPreloade d = new Array(4)

There is no need to specify a length when creating a new array, an
array literal can be used here too:

var imagesPreloaded = [];

>for (var i = 0; i < MyImages.length ; i++)
{
imagesPreloade d[i] = new Image()
imagesPreloade d[i].src=MyImages[i]
}
function Nexter(){

You could replace from here...
>if (currentIndx<im agesPreloaded.l ength-1){
currentIndx=cu rrentIndx+1;
document.theIm age.src=imagesP reloaded[currentIndx].src
}
else {
currentIndx= 0
document.theIm age.src=imagesP reloaded[currentIndx].src
}

to here with something like:

currentIndex = ++currentIndex % imagesPreloaded .length;
document.theIma ge.src = myImages[currentIndx];
Now you need to set the new value for the img element's pbsrc
property, the function might look like:

function nexter() {
currentIndex = ++currentIndex % imagesPreloaded .length;
var img = document.theIma ge;
var src = myImages[currentIndex];

img.src = src;
img.pbsrc = src.replace(/\.jpg$/, '_lrg.jpg');
}
Do a similar thing to backer(), setting the currentIndex will need to
be something like:

currentIndex = currentIndex? --currentIndex || --myImages.length ;

Jul 11 '08 #4
Sorry, news reader defaulted to that Nomen Nescio thing.

Thanks for trying, but this doesn't seem to work.

This:

function nexter() {
currentIndex = ++currentIndex % imagesPreloaded .length;
var img = document.theIma ge;
var src = myImages[currentIndex];

img.src = src;
img.pbsrc = src.replace(/\.jpg$/, '_lrg.jpg');
}

does not change the pbsrc image. It always stays the same as what it is
originally set to in the img tag:

<img src="image1.jpg " NAME="theImage" pbsrc="image1_l rg.jpg"
style="width: 125px; height: 125px;" class="PopBoxIm ageSmall"
onclick="Pop(th is,50,'PopBoxIm ageLarge');" ondblclick="Rev ert
(this,50,'PopBo xImageSmall');" />

So, no matter what nexter changes the small image to, the large image
called by pbsrc is always "image1_lrg.jpg "

Unless I am mistaken, the src attribute of an image can be changed in
this way. But pbsrc isn't an actual img attribute and cannot.

Am I mistaken?

>
Just set it to an appropriate value.

><script language="JavaS cript">

The language attribute is deprecated, type is required:

<script type="text/javascript">

>currentIndx= 0;

All variables should be declared with var:

var currentIndx=0;

>MyImages=new Array();
MyImages[0]='image1.jpg';
MyImages[1]='image2.jpg';
MyImages[2]='image3.jpg';
MyImages[3]='image4.jpg';

By convention, variable names starting with a capital letter are
reserved for constructors. Also, consider using an array literal:

var myImages = ['image1.jpg', 'image2.jpg',
'image3.jpg', 'image4.jpg'];

>imagesPreloade d = new Array(4)

There is no need to specify a length when creating a new array, an
array literal can be used here too:

var imagesPreloaded = [];

>for (var i = 0; i < MyImages.length ; i++)
{
imagesPreloade d[i] = new Image()
imagesPreloade d[i].src=MyImages[i]
}
function Nexter(){

You could replace from here...
>if (currentIndx<im agesPreloaded.l ength-1){
currentIndx=cu rrentIndx+1;
document.theIm age.src=imagesP reloaded[currentIndx].src
}
else {
currentIndx= 0
document.theIm age.src=imagesP reloaded[currentIndx].src
}

to here with something like:

currentIndex = ++currentIndex % imagesPreloaded .length;
document.theIma ge.src = myImages[currentIndx];
Now you need to set the new value for the img element's pbsrc
property, the function might look like:

function nexter() {
currentIndex = ++currentIndex % imagesPreloaded .length;
var img = document.theIma ge;
var src = myImages[currentIndex];

img.src = src;
img.pbsrc = src.replace(/\.jpg$/, '_lrg.jpg');
}
Do a similar thing to backer(), setting the currentIndex will need to
be something like:

currentIndex = currentIndex? --currentIndex || --myImages.length ;


Jul 11 '08 #5
James wrote:
Sorry, news reader defaulted to that Nomen Nescio thing.
Please don't top-post, reply below trimmed quotes.
Thanks for trying, but this doesn't seem to work.

This:

function nexter() {
currentIndex = ++currentIndex % imagesPreloaded .length;
var img = document.theIma ge;
var src = myImages[currentIndex];

img.src = src;
img.pbsrc = src.replace(/\.jpg$/, '_lrg.jpg');
}

does not change the pbsrc image. It always stays the same as what it is
originally set to in the img tag:

<img src="image1.jpg " NAME="theImage" pbsrc="image1_l rg.jpg"
style="width: 125px; height: 125px;" class="PopBoxIm ageSmall"
onclick="Pop(th is,50,'PopBoxIm ageLarge');" ondblclick="Rev ert
(this,50,'PopBo xImageSmall');" />
It is likely that the pop function is using getAttribute to read the
attribute of the elelment rather than reading the DOM property directly.
In that case, use setAttribute:

img.setAttribut e('pbsrc', src.replace(/\.jpg$/, '_lrg.jpg'));
--
Rob
Jul 11 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
7421
by: bissatch | last post by:
Hi, Generally if I re-use code, I use a function. If I need to use these functions over a number of pages I write the function to an include file where all pages have access. So when should I ever use PHP classes instead. I have learned how to put together PHP classes but never seen a reason to use them where I can simply use a function.
6
12203
by: A | last post by:
Hi, How do you make use of nested functions in C++? I realize in C++ that everything must be declared first in a header file before implementation in a .cpp file. I tried to nest a method prototype in another prototype but seems pointless. Can someone please write a short, simple, and concise skeleton code of how to use nested functions? class Foo {
16
2319
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is beginning to get out of hands if I continue to put in extra functionality in the (file-writing) output-functions....
13
1730
by: Simon Dean | last post by:
Hi, I have a couple of questions. If you don't mind. Sorry, I do get a bit wordy at times. First one just throws some thoughts around hoping for answers :-) 1) Anyone got a theory on the usage of PHP Classes rather than an actual technical guide? I've seen loads of things that show how to put together a class, but without actually necessarily saying why you'd want to use a class over say a separate file of functions or explaining:
0
9378
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3914
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 we have to send another system
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.