www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Java if statement issues

  1. #1
    Join Date
    Nov 2009
    Posts
    6

    resolved [RESOLVED] Java if statement issues

    This is a modification to an old script from thread http://www.webdeveloper.com/forum/sh...d.php?t=220013

    This simple java script has worked great and been modified many times as the info banner at the top of the www.psnwa.org web site. One issue I have is that the Photo Society has a monthly online photo competition. The first fifteen days of the month members can enter images, and then the remainder of the month they can vote on the images. Twice a month I have been going out and manually changing the 'Time To Enter' and 'Time to Vote' banners, so I thought I would put in a simple if statement to automatically switch the two.... Or simple I thought as I have played with this and can't seem to get it to run. I am sure I am making a basic mistake, but darn if I can figure it out.

    I am sure the reason is that I am trying to nest an if statement in the arrays. I tried pulling out the if statements and assigning the result to a variable that I then tried to insert into the array without any success either.

    Here is the code as I have it now with the statements at the top to determine the day of the month and the if statements in two places (imgs array and bars array) to change the banner and bar below the banner.

    <!--
    // From: Photographic Society of Northwest Arkansas - http://www.webdeveloper.com/forum/sh...d.php?t=220013

    var curdate = new Date();
    var mday = curdate.getDate();

    var links = ["http://www.psnwa.org/member/portal/Events.php",
    "http://fallphotocompetition.com",
    "http://www.psnwa.org/member/portal/Events.php",
    "http://www.capturearkansas.com/",
    "http://www.psa-photo.org/aboutPageDisplay.asp?DivID=8&menuID=1&pageID=56",
    "http://www.freephotographybooks.com/",
    "http://www.psnwa.org/member/portal/Comp.php"]; // link addresses
    var targets = ["SubMain_Window",
    "_blank",
    "SubMain_Window",
    "_blank",
    "_blank",
    "_blank",
    "SubMain_Window"]; // target addresses
    var imgs = ["http://www.psnwa.org/images/Banner_race_track.jpg",
    "http://www.psnwa.org/images/banner_FFPC.jpg",
    "http://www.psnwa.org/images/banner_yard_sale.jpg",
    "http://www.psnwa.org/images/banner_capture_arkansas.jpg",
    "http://www.psnwa.org/images/banner_join_psa.jpg",
    "http://www.psnwa.org/images/Banner_photographic_therapy.jpg",
    if (mday < "16")
    {
    "http://www.psnwa.org/images/Banner_enter_online_comp.jpg"
    }
    else
    {
    "http://www.psnwa.org/images/banner_vote_post_it.jpg"
    }
    ]; // link images
    var img = []; // preloading array
    var bars = ["http://www.psnwa.org/images/bar_join_us.jpg",
    "http://www.psnwa.org/images/bar_competitions.jpg",
    "http://www.psnwa.org/images/bar_yard_sale.jpg",
    "http://www.psnwa.org/images/bar_competitions.jpg",
    "http://www.psnwa.org/images/bar_join_psa.jpg",
    "http://www.psnwa.org/images/bar_download_book.jpg",
    if (mday < "16")
    {
    "http://www.psnwa.org/images/bar_enter_online.jpg"
    }
    else
    {
    "http://www.psnwa.org/images/bar_vote.jpg"
    }
    ]; // bar images
    var bar = []; // preloading array
    var timeBasis = 8000; // in milli-seconds

    // preload images
    for(i=0; i<imgs.length; i++) { img[i] = new Image(); img[i].src = imgs[i]; }

    // preload bar images
    for(i=0; i<bars.length; i++) { bar[i] = new Image(); bar[i].src = bars[i]; }

    var imgPtr = 0;

    function updateAd(amt){
    if (amt == 0) { imgPtr++; } else { imgPtr += amt; }
    if (imgPtr < 0) { imgPtr = links.length-1; }
    if (imgPtr > links.length-1) { imgPtr = 0; }
    // for testing purposes only
    // document.getElementById('temp').innerHTML = 'imgPtr: '+imgPtr+'<br>amt: '+amt+'<br>img.src:'+img[imgPtr].src;

    document.getElementById('myAd').href = links[imgPtr];
    document.getElementById('myAd').target = targets[imgPtr];
    //document.getElementById('myAd').title = links[imgPtr];
    document.getElementById('myAdBar').href = links[imgPtr];
    document.getElementById('myAdBar').target = targets[imgPtr];
    //document.getElementById('myAdBar').title = links[imgPtr];
    document.getElementById('myAdImg').src = img[imgPtr].src;
    //document.getElementById('myAdImg').alt = img[imgPtr].src;
    document.getElementById('myAdImgBar').src = bar[imgPtr].src;
    //document.getElementById('myAdImgBar').alt = bar[imgPtr].src;
    }

    window.onload = function() {setInterval("updateAd(0)", timeBasis)}

    //-->

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You must assign the url to a variable and compare to number not a string
    Code:
    var urlbanner = (mday < 16)? "http://www.psnwa.org/images/Banner_enter_online_comp.jpg" : "http://www.psnwa.org/images/banner_vote_post_it.jpg";
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2009
    Posts
    6

    Smile Thank you

    I had originally tried with the if statements out of the array, but I must have had a sentex issue, becouse I put in your statement, and the variable into the array and it worked great.

    Thank you again, I had been messing (messing up) with this simple edit for quite some time.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles