View Full Version : Overloading of + and concatenation
dr_bay
09-19-2005, 04:25 PM
I'm having problems trying to get the proper number to display. This code will print out the page numbers so that the user can choose but it starts on page zero. I simply want to change it so that it starts on page one. I need to change the ' + i + ' so that it is i+1 but don't know the proper syntax. I've tried everything. Any help will be appreciated.
function createnumbers(){
for (i=0; i< pic.length; i++) {
document.write('<a href="javascript:changepic(\''+i+'\')">' + i + '</a> ')
}
}
SpirtOfGrandeur
09-19-2005, 04:44 PM
function createnumbers(){
for (i=0; i< pic.length; i++) {
document.write('<a href="javascript:changepic(\''+i+'\')">' + (i+1) + '</a> ')
}
}
nikkiH
09-19-2005, 04:44 PM
Didn't try everything... ;)
changepic(\''+(i+1)+'\')">
dr_bay
09-19-2005, 05:19 PM
That worked! Thanks alot!! :)
One more thing. I'm using this code as a slide show and I would for it to display what number they just clicked on. So it would display something like Image 5 of 11. 5 being the number they just clicked on. I'm sure its something simple again, but I can't figure out how to do it. Any help will be greatly appreciated again. :D
<script language="Javascript">
<!--
var current = 0;
function imageArray()
{
this.length = imageArray.arguments.length;
for (var i = 0; i < this.length; i++)
{
this[i] = imageArray.arguments[i];
}
}
function changepic(which)
{
var goodnum = which;
document.img.src = pic[goodnum];
}
function createnumbers()
{
for (i=0; i< pic.length; i++)
{
document.write('<a href="javascript:changepic(\''+i+'\')">'+ (i+1) +'</a> ')
}
}
var pic = new imageArray(
"CIMG0026.JPG",
"CIMG0228.JPG");
document.write('<img name="img" src="'+pic[0]+'" width="800" height="600">');
document.write("<br>");
createnumbers();
}
// -->
</script>
<br><br>Image # of 11
SpirtOfGrandeur
09-19-2005, 05:32 PM
Image <span id='imgText'>#</span> of 11
function changepic(which)
{
var goodnum = which;
document.img.src = pic[goodnum];
document.getElementById('imgText').innerHTML = which;
}
dr_bay
09-19-2005, 05:46 PM
Thank you once again. :)
Any idea how I can change it so that it displays one number greater than what it actually is. Just like my original problem, it is starting at Image 0 instead of 1. Any help will be appreciated.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.