1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How would I do with with Javascript?

Discussion in 'HTML & Website Design' started by martman, Sep 25, 2010.

  1. #1
    Hi,

    This question regards this website: http://fullwindsoreffect.com

    First let me say that I know there are a ton of coding errors in my website, I have only been doing CSS for two weeks now and am still learning. If you see anything, please point it out. Also, this page will look like crap in IE, so only use firefox, or chrome.

    OK,

    The image of the guy in the suit on the right side of my website... I want to create a list of random dressing tips that will appear in a caption beside him. I want these tips to shuffle through in order each time the page is refreshed. From what I understand, javascript would be used for this? Would the easiest way be jQuery?

    How should I go about doing this? Keep in mind I'm a newb so I want something not too advanced.


    EDIT: Oh, one more thing. Can anyone tell me why the hover on my buttons aren't working?

    UPDATE: I got a javascript array going, but I only figured out how to pull text arrays randomly. How do I make it go in sequence?
     
    Last edited: Sep 25, 2010
    martman, Sep 25, 2010 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    536
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    You should first try to fix those errors,
    and your website shall work in IE too.

    One different dressing tip each time page is refreshed?
    I would think of using javascript cookie to do that.

    Hendra
     
    hdewantara, Sep 26, 2010 IP
  3. martman

    martman Member

    Messages:
    88
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    As I've said, I'm not concerned right now that IE is not rendering page correctly. I am going to make a separate IE.css later.

    I now have gotten the javascript text array to display text strings randomly on page refresh, but how do I make it shuffle through in a sequence?
     
    martman, Sep 26, 2010 IP
  4. hdewantara

    hdewantara Well-Known Member

    Messages:
    536
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #4
    Probably something like below?
    
    ...
    <script type="text/javascript">
    var 
      tips = new Array("tips1","tips2","tips3"),
      current_index = 0,
      timer = setInterval(
      function(){
        var el = document.getElementById("tips");
        if (el){
          clearInterval(timer);
          if (document.cookie.length > 0){
            var cookie_arr = document.cookie.split("="); 
            current_index = parseInt(cookie_arr[1])+1;
            if (current_index > tips.length-1){
              current_index = 0;
            }
          }
          el.textContent = tips[current_index];
          document.cookie = 'current_index='+current_index+';';
        }
      },100);
    </script>
    </head>
    
    <body>
       Tips: <span id="tips"></span>
    ...
    
    HTML:
     
    hdewantara, Sep 26, 2010 IP