PDA

View Full Version : how can i create a function?



faceoff200337
06-16-2008, 04:00 PM
how can i add a hyperlink to each of images??that is what i meant...sorry
for example:
MMimages1[0] = "<a href='test/default.aspx'><img alt='test' src='test1/74650_01.jpg' border='0'></a>";
...any intructions?...thank a lot..

my current code is below:

<script language="JavaScript" type="text/javascript"><!
var MMimages1 = new Array();
MMimages1[0] = "test1/74650_01.jpg";
MMimages1[1] = "test1/74650_02.jpg";
MMimages1[2] = "test1/74650_03.jpg";
MM_preloadImages1(MMimages1);
var timer1 = setTimeout("MM_swapImage1(MMimages1)", 5000);

//></script>

<div id="HeroPhoto"><img src="test1/74650_01.jpg" id="featuredArticle1" border="0"></div>
<div id="FlipControls">
<a onclick="MM_ClickSwap1(-);" href="javascript:void(0)">
<img alt="previous" src="test1/prev.gif" border="0"></a><a onclick="MM_ClickSwap1(+);" href="javascript:void(0)">
<img alt="next" src="test1/next.gif" border="0"></a>
</div>


=======
[MM_ClickSwap1] source code
=======
var i=0;
var a,b;

function MM_ClickSwap1(){

var iClicker = MM_ClickSwap1.arguments[0];

clearTimeout(timer1);

if(iClicker == "-"){
if(i <= 0)
i=MMimages1.length-1;
else
i=i-1;
}else if(iClicker == "+"){
if(i >= MMimages1.length-1)
i=0;
else
i=i+1;
}else{
i=iClicker;
}

MM_Swap1(MMimages1[i]);
timer1 = setTimeout("MM_swapImage1(MMimages1)", 5000);
}



function MM_preloadImages1(){

var d=document;

if(d.images){

if(!d.MM_p)
d.MM_p=new Array();

var index,j=d.MM_p.length,a=MMimages1;

for(index=0; index<a.length; index++){
d.MM_p[j] = new Image;
d.MM_p[j++].src = a[index];
}

}
}



function MM_swapImage1(MMimages1){


a = MMimages1;


if(i<a.length){

MM_Swap1(a[i]);
i++;
timer1 = setTimeout("MM_swapImage1(MMimages1)",5000);

}else{

MM_doSwap1(a[0]);
i=0;

}
}



function MM_Swap1(srcImage){

document.getElementById('featuredArticle1').src = srcImage;
}

codeexploiter
06-17-2008, 06:03 AM
Syntax:
ArrayName[arrayIndex] = "your_image_path/your_image_file_name.extension";


MMimages1[0] = "imgs/one.jpg";
MMimages1[1] = "test/two.gif";
MMimages1[2] = "test1/three.png";
----
----
----
MMimages1[n] = "testn/n.gif";


You can follow the above mentioned method I mean the using the index of the array you can specify new items but you need to increment it by one to access the next location.