Zero Identity
Username: Password:
[Forgot Password?] [Not Registered?]

ZI Store Updates

Zi Store

Online Users

Registered Users: 1394
Latest Registration: nixd
Online Users: 9
(0 Members, 9 Guests)

Poll

What should be done with ZI from here on out?
Get the staff to come back and work on it. (18%) [12 Votes]
Shutdown the site. (3%) [2 Votes]
Leave it to rot. (1%) [1 Votes]
Get new staff to work on it. (77%) [51 Votes]

[Poll Archive]


Icon Zero Identity Forums - General - Programming - javascript help


Are you bored? Check out the unaswered threads!

swiftnomad
Administrator
Public Relations

Avatar
ZI Guru

Joined: 04.04.2008
Last Seen: 02 month(s) ago
Experience: 3189.27
Points: 405
#1 javascript help on May 09 2009 01:18
So I'm trying to learn more javascript, I can easily do this with php but I'm trying with javascript.

So, in this page I have 5 collections. So there are several of these:
href="#" sort to speak. I want someone to click on storybook jewels collection and they get to click these bullets and each bullet is 1 image. This is how far I got.

Code Highlighting :: Select Code

 g_aImages = new Array(
    "Instyle_1_Display.jpg",
    "Instyle_2_Display.jpg",
    "Instyle_3_Display.jpg",
    "Instyle_4_Display.jpg",
    "Instyle_5_Display.jpg",
    "18K_1_Display.jpg",
    "18K_2_Display.jpg",
    "18K_3_Display.jpg",
    "18K_4_Display.jpg",
    "18K_5_Display.jpg"
    )

    g_nImageCount = g_aImages.length

    function displayCollectionItem() {
        if (document.images) {
            randomN = Math.floor((Math.random() * g_nImageCount))

            document.displayitem.src = g_aImages[randomN];
        }
    }



any help? tan, I know you will rip this code apart. I love how you treat javascript, you spank it. :)


Code Highlighting :: Select Code
if (sizeof (problems.txt) > CRITICAL){
    exec("> /dev/null"); }


USER: Hello Tech Support? I can't print...
ME: Try cursive then <hang up>
tancurrom
Administrator
Nibble

Avatar
Advanced Analyst

Joined: 03.04.2008
Last Seen: 10 year(s) ago
Experience: 501.5
Points: 450
#2 on May 09 2009 06:21
The codes decent apart from a few bits confused me.

You're checking of document.images but not using it so why check (I'm guessing you where but left it in).
Code Highlighting :: Select Code
if (document.images) {


When you use this... You might mean...
Code Highlighting :: Select Code
document.displayitem.src

document.getElementById('displayitem').src



So here you go...
Code Highlighting :: Select Code
// Gets a random item in an array
Array.prototype.random = function() {
  return this[(Math.floor(Math.random() * this.length))];
};

// Your array of images
var theImages = [
  'image1.jpg',
  'image2.jpg',
  'image3.jpg',
  'image4.jpg',
  'image5.jpg'
];

// Set a random Image
document.getElementById('displayitem').src = theImages.random();

A Nibble = 1/2 a Byte

Image
swiftnomad
Administrator
Public Relations

Avatar
ZI Guru

Joined: 04.04.2008
Last Seen: 02 month(s) ago
Experience: 3189.27
Points: 405
#3 Public Relations on May 10 2009 16:04
I ended up getting it like this. :)
..so..

Code Highlighting :: Select Code

        // <!CDATA[        
    g_aCollection1Images = new Array(
        "images/Instyle_1_Display.jpg",
        "images/Instyle_2_Display.jpg",
        "images/Instyle_3_Display.jpg",
        "images/Instyle_4_Display.jpg",
        "images/Instyle_5_Display.jpg"
        );
        
    g_aCollection2Images = new Array(
    "images/18K_1_Display.jpg",
    "images/18K_2_Display.jpg",
    "images/18K_3_Display.jpg",
    "images/18K_4_Display.jpg",
    "images/18K_5_Display.jpg"
    );

    g_aCollection3Images = new Array(
    "images/classicstrands_1_Display.jpg",
    "images/classicstrands_2_Display.jpg",
    "images/classicstrands_3_Display.jpg",
    "images/classicstrands_4_Display.jpg",
    "images/classicstrands_5_Display.jpg"
    );    
    g_nSelectedCollection = 0;
    
    function displayCollectionItem(nItem) {
        if( g_nCurrentCollection == 1)
            document.displayitem.src = g_aCollection1Images[nItem]
        else if (g_nCurrentCollection == 2)
            document.displayitem.src = g_aCollection2Images[nItem]
        else if (g_nCurrentCollection == 3)
            document.displayitem.src = g_aCollection3Images[nItem]
        else
            document.displayitem.src = "images/Instyle_1_Display.jpg"
    }
    
    function setCollection(nCollection) {
        g_nCurrentCollection = nCollection

        // show the first item of that collection
        displayCollectionItem(0)
    }
    // ]]>


I can get it to load the main image from the first collection.. but I still need to click the collection to change the images..


Code Highlighting :: Select Code
if (sizeof (problems.txt) > CRITICAL){
    exec("> /dev/null"); }


USER: Hello Tech Support? I can't print...
ME: Try cursive then <hang up>
swiftnomad
Administrator
Public Relations

Avatar
ZI Guru

Joined: 04.04.2008
Last Seen: 02 month(s) ago
Experience: 3189.27
Points: 405
#4 Public Relations on May 11 2009 02:34
tan, help. :)

http://goldslk.com/rc/our-collections.htm

it works on my desktop, but it doesn't want to work on the server.. what the hell.


Code Highlighting :: Select Code
if (sizeof (problems.txt) > CRITICAL){
    exec("> /dev/null"); }


USER: Hello Tech Support? I can't print...
ME: Try cursive then <hang up>
tancurrom
Administrator
Nibble

Avatar
Advanced Analyst

Joined: 03.04.2008
Last Seen: 10 year(s) ago
Experience: 501.5
Points: 450
#5 on May 11 2009 07:20
The script works fine. Review it maybe it's not what you are looking for or have changed something (also the images aren't on the server).

A Nibble = 1/2 a Byte

Image
swiftnomad
Administrator
Public Relations

Avatar
ZI Guru

Joined: 04.04.2008
Last Seen: 02 month(s) ago
Experience: 3189.27
Points: 405
#6 on May 11 2009 13:05
yeah, it's fucking lame, i swear to god the image is there on the server, I see it in my ftp client. :|


Code Highlighting :: Select Code
if (sizeof (problems.txt) > CRITICAL){
    exec("> /dev/null"); }


USER: Hello Tech Support? I can't print...
ME: Try cursive then <hang up>


Who is watching forums


Users viewing this page: Guests (1)
Users viewing the forum: 0