Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2005
    Location
    Pennsylvania
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Overloading of + and concatenation

    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> ')
    }
    }

  • #2
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function createnumbers(){
    for (i=0; i< pic.length; i++) {
    document.write('<a href="javascript:changepic(\''+i+'\')">' + (i+1) + '</a> ')
    }
    }
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Didn't try everything...

    changepic(\''+(i+1)+'\')">

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    New Coder
    Join Date
    Sep 2005
    Location
    Pennsylvania
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

    <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>&nbsp;&nbsp; ')
    }
    }

    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

  • #5
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Image <span id='imgText'>#</span> of 11
    Code:
    function changepic(which)
    {
    var goodnum = which;
    document.img.src = pic[goodnum];
    document.getElementById('imgText').innerHTML = which; 
    }
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #6
    New Coder
    Join Date
    Sep 2005
    Location
    Pennsylvania
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    Last edited by dr_bay; 09-20-2005 at 12:00 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •