/    Sign up×
Community /Pin to ProfileBookmark

using GetElementById for simple image gallery

hey guys,

having a little trouble trying to get a script to work. what i’m trying to do is make a very simple image gallery – you have a space for the big image that is loaded, and underneath will be little thumbnails of the pictures that you can load. when you click on one of those thumbnails it will load the full-sized version in the big image area. the big image area and the thumbnail image area are in separate divs, the big image one nested in the little one. it’s also linking to an external javascript file.

this is the code for my javascript file:

[code=php]<script language=”JavaScript”>
function LoadGallery(image,filename) {
document.GetElementById(image).src = filename;
}
</script>[/code]

and this is how it looks in my html:

[code=php]<div id=”littlepics”>
<div id=”bigpic”>
<img src=”images/step1/step1.jpg” width=”480″ height=”320″ id=”bigimage”>
<p>Step 1: Meet in person – do not rely on email or the telephone.</p>
</div>
<a href=”#_self” onclick=”LoadGallery(‘bigimage’,’images/step1/step1.jpg’)”><img src=”images/step1/thumbs/step1.jpg”></a>
<a href=”#_self” onclick=”LoadGallery(‘bigimage’,’images/step1/email1.jpg’)”><img src=”images/step1/thumbs/email1.jpg”></a>
<a href=”#_self” onclick=”LoadGallery(‘bigimage’,’images/step1/email2.jpg’)”><img src=”images/step1/thumbs/email2.jpg”></a>
<a href=”#_self” onclick=”LoadGallery(‘bigimage’,’images/step1/email3.jpg’)”><img src=”images/step1/thumbs/email3.jpg”></a>
<a href=”#_self” onclick=”LoadGallery(‘bigimage’,’images/step1/jenrachel.JPG’)”><img src=”images/step1/thumbs/jenrachel.JPG”></a>
</div>
</div>[/code]

click <a href=”http://a.parsons.edu/~jrandolph/seriousblab/1.html”>here</a> to see it in action.

*steps i’ve tried to correct the issue*
1. checked all syntax, paths and refs.
2. removed the doctype in my html file.
3. putting the thumbnail code in the same div as the big image code.
4. changed the thumbnail link attributes to onclick=”LoadGallery(‘bigpic.bigimage’) in case it didn’t know where “bigimage” was supposed to be.
5. changed the big image tag attributes to img name=”bigimage” instead of img id=”bigimage” in case this was some kind of problem w/ the doctype or something.
6. had multiple people check my code for syntax.

i am trying to view this page in Safari browser 1.3 (v312) which does support this – i’ve seen people do similar photo galleries on other sites.

if anyone can give me some kind of advice i’d really appreciate it, and thank you very much for your time in advance. ?

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsMay 05.2005 — document.GetElementById(image).???????????

use

document.getElementById(image).

also

<a href="#_self" onclick="LoadGallery('bigimage','images/step1/step1.jpg')"><img src="images/step1/thumbs/step1.jpg"></a>

better as unless you want the border

<img src="images/step1/thumbs/step1.jpg" onclick="LoadGallery('bigimage','images/step1/step1.jpg')">
Copy linkTweet thisAlerts:
@kendokendokendoauthorMay 05.2005 — hey, just to clarify

do you mean that i should use
[code=php]document.getElementById(image).src[/code]

or do you mean that i should use
[code=php]document.getElementById(image)[/code] without the .src part?

and thanks very much!
Copy linkTweet thisAlerts:
@KorMay 05.2005 — 
  • 1. [COLOR=Red]document.getElementById('foo')[/COLOR] is the referenced object. To reference the object using this method, your object [b]must[/b] have an id


  • <img src="mypic.jpg" id="foo">

    Objects have properties (attributes). Properties have values.

    One of the objects' property is [b]src[/b]

    thus

    2. [COLOR=Red]document.getElementById('foo').src[/COLOR] is a property

    It's value is the relative/absolute url of your picture
    Copy linkTweet thisAlerts:
    @kendokendokendoauthorMay 05.2005 — hey kor and vw,

    thanks for your help. i've tried modifying my code in both ways you suggested but both aren't working for me.

    just to check the syntax this is what i did in both instances:

    vw suggestion- [code=php]<script language="JavaScript">
    function LoadGallery(image,filename) {
    document.getElementById(image) = filename;
    }
    </script>[/code]


    kor suggestion- [code=php]<script language="JavaScript">
    function LoadGallery(image,filename) {
    document.getElementById('bigimage').src = filename;
    }
    </script>[/code]


    with my html looking like [code=php]<div id="littlepics">
    <div id="bigpic">
    <img src="images/step1/step1.jpg" width="480" height="320" id="bigimage">
    <p>Step 1: Meet in person - do not rely on email or the telephone.</p>
    </div>
    <a href="#_self" onclick="LoadGallery('bigimage','images/step1/step1.jpg')"><img src="images/step1/thumbs/step1.jpg"></a>
    <a href="#_self" onclick="LoadGallery('bigimage','images/step1/email1.jpg')"><img src="images/step1/thumbs/email1.jpg"></a>
    <a href="#_self" onclick="LoadGallery('bigimage','images/step1/email2.jpg')"><img src="images/step1/thumbs/email2.jpg"></a>
    <a href="#_self" onclick="LoadGallery('bigimage','images/step1/email3.jpg')"><img src="images/step1/thumbs/email3.jpg"></a>
    <a href="#_self" onclick="LoadGallery('bigimage','images/step1/jenrachel.JPG')"><img src="images/step1/thumbs/jenrachel.JPG"></a>
    </div>
    </div>[/code]
    Copy linkTweet thisAlerts:
    @scragarMay 05.2005 — [code=php]<script type="text/javascript"><!--
    function LoadGallery(image, UrlFrom){
    document.getElementById(image).src = UrlFrom.src;
    }
    //-->
    </script>
    .....
    <div id="littlepics">
    <div id="bigpic">
    <img src="images/step1/step1.jpg" width="480" height="320" id="bigimage">
    <p>Step 1: Meet in person - do not rely on email or the telephone.</p>
    </div>
    <img src="images/step1/thumbs/step1.jpg" onclick="LoadGallery('bigimage',this);">
    <img src="images/step1/email1.jpg" onclick="LoadGallery('bigimage',this);">
    <img src="images/step1/email2.jpg" onclick="LoadGallery('bigimage',this);">
    <img src="images/step1/email3.jpg" onclick="LoadGallery('bigimage',this);">
    <img src="images/step1/thumbs/jenrachel.JPG" onclick="LoadGallery('bigimage',this);">
    </div>

    </div> [/code]

    a few points for you to think about:

    paragraphs's should not go in divs according to the w3 validator.

    you close one more div than you open.
    Copy linkTweet thisAlerts:
    @KorMay 05.2005 — 
    paragraphs's should not go in divs according to the w3 validator.
    [/quote]

    My advice is to insert text in <span></span> tags and position them using CSS rather than using <p></p> tags inside a div.
    Copy linkTweet thisAlerts:
    @kendokendokendoauthorMay 05.2005 — scragar,

    thanks soo much for your help - this really worked out. also thanks for catching my extra div tag.

    one issue now with [code=php]<img src="images/step1/thumbs/step1.jpg" onclick="LoadGallery('bigimage',this);">[/code]

    "this" is referring to "images/step1/thumbs/step1.jpg" but i would like it to refer to and load a different image. the thumbnail is really just a link. i am not quite sure how to tell it to load a different image - tried changing "this" to the path of the image i would like it to load but it's not working so obviously i've got the wrong idea.

    think you could help me out with this last one?

    thanks so much
    Copy linkTweet thisAlerts:
    @scragarMay 05.2005 — You should now be able to use either this, or the URL to pass the image URL.

    [code=php]<script type="text/javascript"><!--
    function LoadGallery(image, UrlFrom){
    if(typeof UrlFrom == "object" || UrlFrom == "[object]"){
    document.getElementById(image).src = UrlFrom.src;
    }else{
    document.getElementById(image).src = UrlFrom;
    };
    };
    //-->
    </script>
    .....
    <div id="littlepics">
    <div id="bigpic">
    <img src="images/step1/step1.jpg" width="480" height="320" id="bigimage">
    <p>Step 1: Meet in person - do not rely on email or the telephone.</p>
    </div>
    <img src="images/step1/thumbs/step1.jpg" onclick="LoadGallery('bigimage',this);">
    <img src="images/step1/email1.jpg" onclick="LoadGallery('bigimage','images/step1/email2.jpg');">
    <img src="images/step1/email2.jpg" onclick="LoadGallery('bigimage','images/step1/email1.jpg');">
    <img src="images/step1/email3.jpg" onclick="LoadGallery('bigimage',this);">
    <img src="images/step1/thumbs/jenrachel.JPG" onclick="LoadGallery('bigimage',this);">
    </div>[/code]
    Copy linkTweet thisAlerts:
    @kendokendokendoauthorMay 05.2005 — scragar,

    thanks so much for your help. this works great.
    Copy linkTweet thisAlerts:
    @JeffreygizDec 19.2014 — money in minutes loan

    [url=http://paydayloansonlinexl.com]payday loans[/url] <a href="http://paydayloansonlinexl.com">payday loans</a> moneylender

    [url=http://personal-loans4badcredit.com]personal loans[/url] <a href="http://personal-loans4badcredit.com">personal loans</a> how to make quick cash in a day

    [url=http://paydayloansonlinegt.com]payday loans online[/url] <a href="http://paydayloansonlinegt.com">payday loans online</a> easy loan online

    [url=http://personalloans4badcredit.com]personal loan[/url] <a href="http://personalloans4badcredit.com">personal loan</a> personal money loans

    [url=http://getloansforbadcredit.com]loans for bad credit[/url] <a href="http://getloansforbadcredit.com">loans for bad credit</a> bad credit loans nc

    [url=http://cashadvanceonlinexl.com]cash advance[/url] <a href="http://cashadvanceonlinexl.com">cash advance</a> small quick loans

    [url=http://badcreditloansxl.com]bad credit loans[/url] <a href="http://badcreditloansxl.com">bad credit loans</a>

    installment loans online no credit check

    [url=http://paydayloanonlinexl.com]payday loan[/url] <a href="http://paydayloanonlinexl.com">payday loan</a>

    yes cash loans

    [url=http://cashloansonlinexl.com]cash loans[/url] <a href="http://cashloansonlinexl.com">cash loans</a>

    loans instant

    [url=http://loansnocreditcheckxl.com]no credit check loans[/url] <a href="http://loansnocreditcheckxl.com">no credit check loans</a> indiana payday loans

    viagra vs viagra blogs guestbook.php?do=

    [url=http://viagraonline-us.com]viagra online[/url] <a href="http://viagraonline-us.com">viagra online</a>

    cialis 20mg canada administrators

    [url=http://pharmshop-online.com]cialis online[/url] <a href="http://pharmshop-online.com">cialis online</a>

    abrupt discontinuence of cialis

    [url=http://genericlevitra-usa.com]buy levitra[/url] <a href="http://genericlevitra-usa.com">buy levitra</a> - buyy generic levitra
    ×

    Success!

    Help @kendokendokendo spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...