SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting a indication of what parent ID attribute the particular page I am on reads?

    Hi-
    I am creating a site with the thumbnail gallery which will lead to bigger picture pages of the thumbnails by clicking on them. Pretty standard. However I wish to do something a bit more complicated than just this. I have a timed JavaScript slideshow that's just working fine and will also contain the pictures of all the thumbnails in big picture form. So what I want to do is have my slideshow start from an index in the array that holds the images according to the page the user is on. I mean there will be slideshow controls in the head of the big picture pages as well as prev next buttons. So the user will have a choice of going to a slideshow or using the prev next buttons. If the user is on big picture page 6 I will want the index into the slideshow to be on index 5 and so on. I have not done too much Java scripting which is this complicated, but what follows is the code of my attempt to get an indication of the page I'm on.

    var picHolder = document.getElementById("slide").parentNode;
    var picNum = picHolder.getAttribute(0);
    alert(picNum);

    So what I am trying to do is put all my big picture in div tags surrounding the image tags that hold the images. Then have the div tags ID, first attribute, according to which big picture page I'm on. And the code above is my experimental attempt to programmatically get an indication of which big picture page I am on. My intention would then be to use a switch statement to programmatically change the start index into my slideshow array. The code above returns a null. So how do I do this correctly.

    Your help would be very appreciated.
    Marc

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you saying that your pages are numbered, each one loads your script and you want this script to determine the current page's number? If so, what is the numbering scheme?

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali
    Are you saying that your pages are numbered, each one loads your script and you want this script to determine the current page's number? If so, what is the numbering scheme?
    Yes that's what I am saying. The numbering scheme is this the first previous next thumbnail linked big picture expansion page has a div tag, which surrounds the picture or img tag, with an ID of P1 in the second page of this type has ID p2 on its div attribute and so on. I will like to let the user start the same slideshow that goes around and around from different entry points according to witch big picture expansion page the user is that. I mean if the users at the first big picture thumbnail expansion page the slideshow if turned on from that page will start at array index 0. And if the use is on the 20th big picture thumbnail big picture expansion page the array index would be 19 with that page having an ID attribute on the div tag of p20. and so on.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I meant what is the numbering scheme of the actual filenames?

    I.E. is it: FixedName+VaryingNumber.extension or what?

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali
    I meant what is the numbering scheme of the actual filenames?

    I.E. is it: FixedName+VaryingNumber.extension or what?
    Well the actual filenames will be GaS1.html, GaS2.html, GaS3.html, GaS4.html and so on. Do you have what you know is a better plan for me than the reading of the parents tag attribute I was planning on? Or do you just have one you know will work. Either way I would be very appreciative since I know what ever way you have is something I should definitely learn.
    Sincerely
    Marc
    Last edited by MarcMiller; Oct 27, 2006 at 12:54. Reason: selling

  6. #6
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MarcMiller
    Well the actual filenames will be GaS1.html, GaS2.html, GaS3.html, GaS4.html
    As I thought, in which case the following statement should extract the number from the filename and convert it to the required index:
    Code:
    var index=location.href.split('?')[0].match(/0*(\d+)\.\w+$/)[1]-1;

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot.

    That index will be passed to my setup routine in a separate behavior layer and not in embedded JavaScript. Will that make any difference. It will be passed to my setup routine like this.

    window.onload = function () {
    document.getElementById("textOverW2").firstChild.nodeValue="Slideshow off";
    document.getElementById("turnOnSlides").onclick=onClickToggle;
    document.getElementById("Faster").onclick=onClickFaster;
    document.getElementById("Slower").onclick=onClickSlower;
    var index=location.href.split('?')[0].match(/0*(\d+)\.\w+$/)[1]-1;
    slideitSetup(slidesChangingAt, index);/* var index=location.href.split('?')[0].match(/0*(\d+)\.\w+$/)[1]-1;
    proposed passing to slideshow set up routine of slideshow index */

    setTimeout("slideit()", 5000);
    }

    I am not familiar with the code you are using could you give me links to some sort of explanation tutorial or tutorial like page that would better explain what you are doing? Or alternatively give me more of an explanation here.
    Thanks again
    Marc
    Last edited by MarcMiller; Oct 27, 2006 at 15:08. Reason: formatting

  8. #8
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MarcMiller
    Thanks a lot.

    That index will be passed to my setup routine in a separate behavior layer and not in embedded JavaScript. Will that make any difference. It will be passed to my setup routine like this.

    window.onload = function () {
    document.getElementById("textOverW2").firstChild.nodeValue="Slideshow off";
    document.getElementById("turnOnSlides").onclick=onClickToggle;
    document.getElementById("Faster").onclick=onClickFaster;
    document.getElementById("Slower").onclick=onClickSlower;
    var index=location.href.split('?')[0].match(/0*(\d+)\.\w+$/)[1]-1;
    slideitSetup(slidesChangingAt, index);/* var index=location.href.split('?')[0].match(/0*(\d+)\.\w+$/)[1]-1;
    proposed passing to slideshow set up routine of slideshow index */

    setTimeout("slideit()", 5000);
    }
    I think that should be O.K.
    I am not familiar with the code you are using could you give me links to some sort of explanation tutorial or tutorial like page that would better explain what you are doing? Or alternatively give me more of an explanation here.
    location.href is split across '?' to separate the url from any passed parameters, then String.match uses a regular expression to search for a set of digits (optionally preceded by 0s) followed by a period then a set of alphanumeric characters followed by the end of the string. The found substring of digits is retrieved from the returned array and converted to a number by the subtraction of 1, which yields the required array subscript.

  9. #9
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My regular expression only doesn't work in Internet Explorer?

    Hi-
    quite a while ago on this thread I post a question on how to start my timed slight changing JavaScript slideshow to start with the next picture of what ever the particular page I was on was showing. I have a site I am building with prev and next buttons which lets you see a series of pictures using these buttons or start a slideshow from any of these pages with control buttons on top of each of these pages. So a member here named "Logic Ali" was nice enough to give me a regular expression which would do this for me. I thought that was just great and it is, however I have found a bug. This regular expression gives me the index into my slideshow of the next slide only with URLs numbered with endings of 1 through 9 in Internet Explorer. However in Firefox it gives me the correct index for all your are else ending with endings of 1 through 27. It seems that you are else with endings of 2 digits is beyond the capability of this regular expression in Internet Explorer but not in Firefox. I could certainly change my numbering system to be URL endings from 01 through 27 to make those digit lengths uniform but this would only compound the problem for Internet Explorer. I will show the code below and asked if you have a solution for me or can tell me how to start solving it myself. My present JavaScript debugger's are Firefox based and I am clueless as to how to start solving this problem. So please look over the code with the regular expressionas it is used in my code below. I have commented out the offending code and explicitly coded a zero starting point to show you what is working for me now. This commented out code appears in red. The green code is my explicit index code of zero. Also below are two links one which works in Internet Explorer with an explicit zero Index for my picture changing starting point in another that only works in Firefox beyond URLs ending in one digit.

    Code:
    window.onload = function () {
    document.getElementById("textOverW2").firstChild.nodeValue="Slideshow off";
    document.getElementById("turnOnSlides").onclick=onClickToggle;
    document.getElementById("Faster").onclick=onClickFaster;
    document.getElementById("Slower").onclick=onClickSlower;
    //slideNumber=location.href.split('?')[0].match(/0*(\d+)\.\w+$/)[1]-1;      
     var slideNumber=0;      
    slideitSetup(slidesChangingAt, slideNumber );
    setTimeout("slideit()", 5000);
    }
    page link to code that works in Firefox you are else ending in 1 through 27 but in only works in Internet Explorer in URLs ending in 1 through 9

    code that works in both Internet Explorer and Firefox but always starts from picture one regardless of the URL ending you are starting from

  10. #10
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Logic Ali- thank you very much for your continued interest in helping me. I feel embarrassed that I had not realized I failed to update my array to 27 members with the rest of my code and there is no problem with the regular expression you have given me in Internet Explorer or Firefox, it was just my mistake.

    Very sincerely and embarrassed
    Marc


Bookmarks

Posting Permissions

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