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 12 of 12
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    only show picture once

    if i have a code like this it loads a image then when clicked upon it change image if i have sevreal people looking at the page can i do something so it only show the image after clicking from the imglist only once can the program remember what was displayed from other visitors im tryin to give each visitor a diffrent image

    would be great if you have any ideas on the subject

    nellan



    [var baseURL = 'image/';
    var imgList = ['owl1982.jpg','owl1956.jpg','owl2056.jpg','owl5674.jpg];

    function changeImage() {
    var rndno = Math.floor(Math.random()*imgList.length);
    document.getElementById('rndImage').src = baseURL+imgList[rndno];
    }
    // onload = function() { changeImage(); }
    </script>

    </head>
    <body>
    <img src='image' id="rndImage" onclick="changeImage()">]

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    you would need server side code for that.

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by patryk View Post
    you would need server side code for that.
    That is very true, but depending on how many images you have you could go some way to achieve this by showing an image based on the time (in seconds) that the user enters the site (or clicks the image to change it). Obviously that does not work if two or more users enter the site or click the image at exactly the same moment. It will also be unreliable if you only have four (or a small number of) images.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    If you try to do this client side (javascript) then you're only going to get a half a$$ solution at best which is what philip_m was suggesting. I don't see the point in making a suggestion and then say that it won't work in many cases.

    Anyway, forget javascript for this. If you want to do it PROPERLY then you could use php and a database or any other similar server side language.

    With php, once you have created your db table, then it's only a few lines of php code to do what you want.

  • #5
    New Coder
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    That is very true, but depending on how many images you have you could go some way to achieve this by showing an image based on the time (in seconds) that the user enters the site (or clicks the image to change it). Obviously that does not work if two or more users enter the site or click the image at exactly the same moment. It will also be unreliable if you only have four (or a small number of) images.
    are you thinking that if i use time i dont need show only once function or suggestion are ment to be time plus only show once for that particular time the user is on its on a jumping page for a tournement so they will only be there a little while for registration

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by nellan View Post
    are you thinking that if i use time i dont need show only once function or suggestion are ment to be time plus only show once for that particular time the user is on its on a jumping page for a tournement so they will only be there a little while for registration
    Sorry, there seems to be a language problem, I do not understand you.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    New Coder
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Sorry, there seems to be a language problem, I do not understand you.
    Sorry english not my main langue.
    What I ment if I use time and with that I thought you ment it shows for a few seconds then change but perhaps you ment to use the actually time that the clock is? So if its 3 pm it show one image and and then next perhaps one minute later? I was not sure how you ment in your post and if to use show only once function ?
    Its only a page that I do for a specifik game and time so they register on it to be in the game.But I put images on it and my effort was to give only one picture per visitor. As it is now it shows images when clicked upon it shows a random image but sometimes the visitor clicks again and gets of course then a diffrent image.Im thankful that you took the time to answer and once again sorry for my problems with the langue.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by nellan View Post
    Sorry english not my main langue.
    What I ment if I use time and with that I thought you ment it shows for a few seconds then change but perhaps you ment to use the actually time that the clock is? So if its 3 pm it show one image and and then next perhaps one minute later? I was not sure how you ment in your post and if to use show only once function ?
    Its only a page that I do for a specifik game and time so they register on it to be in the game.But I put images on it and my effort was to give only one picture per visitor. As it is now it shows images when clicked upon it shows a random image but sometimes the visitor clicks again and gets of course then a diffrent image.Im thankful that you took the time to answer and once again sorry for my problems with the langue.
    I am afraid that I still do not understand what you are trying to achieve. Please try to say clearly what you want to happen when a user visits your website. By time I meant the actual time by the clock that the user enters the site. The user sees a single image, and that image is determined by the clock time, so different users entering the site at a different time will see a different image. If you want to change that image after a period of time say every minute) that is a completely different thing.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    New Coder
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    I am afraid that I still do not understand what you are trying to achieve. Please try to say clearly what you want to happen when a user visits your website. By time I meant the actual time by the clock that the user enters the site. The user sees a single image, and that image is determined by the clock time, so different users entering the site at a different time will see a different image. If you want to change that image after a period of time say every minute) that is a completely different thing.
    I want to make certain that a image only goes to one visitor so next vistor gets another image there are a limited number of persons entering the page I could achieve it with clock but then I need alot of images because the page it self is up sevreal hours so even with only 4 people entering I dont know when they enter therefor I thought with limited pictures and some code that a image been displayed to another visitor it will not show again but I guess I need server code then I will see if i can learn that
    Thank you for your help

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by nellan View Post
    ut I guess I need server code then I will see if i can learn that.
    Yes, you really need server-side code.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #11
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    It's not possible to store the range of the image in a cookie ?
    Then see, for example, this PPK cookies functions.

  • #12
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by 007julien View Post
    It's not possible to store the range of the image in a cookie ?
    Then see, for example, this PPK cookies functions.
    How can client-side cookies help?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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