Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:01:32+00:00 2026-05-25T15:01:32+00:00

I am currently coding a gallery which until now has been combining AJAX and

  • 0

I am currently coding a gallery which until now has been combining AJAX and Javascript with an xml-file to load all images. Now I have come to the fun part where I click an image to enter the inner gallery. (On the first page they load one image of each session and when one image is pressed it will continue to the rest of the images of that session.)

The problem that I have with AJAX (I’m sure there is a neat hack for this as well!) is that when the page is reloaded it automatic goes back to the session index since there is no URL-change.

What I have done now, so far is to put one javascript-function in one document where it loads only the gallery index. This works flawless.

In the other file I got just about the same code, but instead it loads the function that loads the rest of the session-images, but I don’t get it to work.

Here is the script that should load the specific session-images.

<script type="text/javascript">
    window.onload = displayGallery(<?php echo $_GET['session']; ?>);
</script>

<div id="gallery">

</div>

When I just only javascript and an “onload” in the link it worked just fine, but then I had the problem to reload the page. Now I just php to include this file and $_GET the variable for “displayGallery()”

function displayGallery(sessionAtt)

So in an attempt to make this clear, I’m rubbish explaining stuff, I need help with making the displayGallery(sessionAtt) actually run after grabbing the essential variable from the url.

I am VERY fresh on Javascript. Done most scripts in php up until now.

EDIT:

To explain the site a bit: It’s a gallery I’m making for a friend of mine. There is no login for anyone else but her and all sub-pages (Start, Gallery, About, etc.) is loaded through php “include”.

The XML:

<gallery>
    <session>
        <sessionName>Beauty</sessionName>
        <path>gallery/beauty/</path>
        <item>
            <file>_DSC2331.jpg</file>
            <name>Picture 1</name>
        </item>
        <item>
            <file>_DSC2339.jpg</file>
            <name>Picture 2</name>
        </item>
        <item>
            <file>_DSC2350.jpg</file>
            <name>Picture 3</name>
        </item>
        <date>2011-08-03</date>
    </session>
    <session>
        <sessionName>Red</sessionName>
        <path>gallery/red/</path>
        <item>
            <file>_MG_6227-web.jpg</file>
            <name>Picture 1</name>
        </item>
        <item>
            <file>_MG_6235-web.jpg</file>
            <name>Picture 2</name>
        </item>
        <item>
            <file>_MG_6240-cropped-web.jpg</file>
            <name>Picture 3</name>
        </item>
        <date>2011-08-03</date>
    </session>
</gallery>

The js:

function displayGallery(sessionAtt)
{
    var xmlDoc = loadDoc("gallery/gallery.xml");
    var sessions = xmlDoc.getElementsByTagName("session");
    var txt = getGallery(sessions, sessionAtt);
    document.getElementById("gallery").innerHTML = txt;
}

function getGallery(sessions, sessionAtt) {
    var items = null,
    i = 0,
    j = 0,
    sessionName = "",
    link = "",
    img = "",
    path = "",
    file = "",
    txt = "";
    for (i = 0; i < sessions.length; i++) { 
        sessionName = sessions[i].getElementsByTagName("sessionName")[0].childNodes[0].nodeValue;
        if(sessionName == sessionAtt)
        {
            items = sessions[i].getElementsByTagName("item");
            path = sessions[i].getElementsByTagName("path")[0].childNodes[0].nodeValue;
            for (j = 0; j < items.length; j++) {
                file = items[j].getElementsByTagName("file")[0].childNodes[0].nodeValue;
                link = '<a href="' + path + file + '" rel="lightbox[' + sessionName + ']" title="' + sessionName + '">';
                img = '<img src="' + path + file + '" class="thumb" onclick="displayImage();" /></a>';
                txt += link + img;
            }
        }
    }
    return txt;
}

I have tried to run the script with sessionAtt set in the function and it works.

window.onload = displayGallery;

But when changing it to

window.onload = displayGallery('Red');

both manually and with php… Nothing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:01:33+00:00Added an answer on May 25, 2026 at 3:01 pm

    Your code is working fine for me. The only thing I did differently is I used <body onload="displayGallery('Red')"> rather than window.onload = displayGallery('Red');

    As Martin pointed out, using window.onload tries to find <div id='gallery'> before the page is loaded, giving an error: document.getElementById(“gallery”) is null

    Using <body onload="displayGallery('Red')"> waits for the page to finish loading before calling displayGallery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been coding in J2SE and now I'm currently working on a project that
I am currently coding an app which calls a text file from a store,
I am currently coding a simple Data Access Layer, and I was wondering which
I've been working through the Stanford iPhone Coding course and currently hooking into the
A class I am taking currently requires us to do all of our coding
I'm currently coding a product which will have only one database but will host
I'm currently coding an app that has hotkey functionality, I've done some reading and
I'm currently coding a button which will delete a record from a database if
Currently I'm trying to create some coding short cuts for our website. Right now
Currently I'm learning all the stuff around key-value coding. In the docs they say:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.