SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript fails in Firefox, Opera

    I have a routine that works fine in IE, but mysteriously, without an error code or other indication of failure, does not execuate in FireFox or Opera.

    The page is here

    http://iiswebdev.pacific.edu/default.asp

    The function code is

    /* Validate date of event items BPhelps 10/13/2005 */
    function newitem(StartDate, ExpireDate, url, img, alt, sLinkText, sLongDesc)
    {
    tempdate = new Date();
    var mon = tempdate.getMonth()+1;
    var day = tempdate.getDate();
    var year = tempdate.getYear();

    if (mon < 10) {
    mon = "0" + mon;
    }
    if (day<10) {
    day = "0" + day;
    }
    today = year +""+ mon +""+ day

    if ((today < ExpireDate) && (today > StartDate)) {
    document.write("<tr\><td width='65'\><a href='" + url + "'\>")
    document.write("<img src='" + img + "'alt='" + alt + "' width='65' height='65' border='0'\></a>")
    document.write("</td\><td valign=\"top\"\><div class=\"EventText\"\><a href=\"" + url + "\" class=\"EventText\"\>" + sLinkText + "</a\>")
    document.write("</div\><br\><span class=\"sitemapSecondLvl\"\>" + sLongDesc + "</span\></td\></tr\>")
    }
    }

    the function call looks like this

    <script language="JavaScript" type="text/javascript">
    <!--
    newitem("20051012","20051029","../path/fname.asp","../path/img.jpg","ALT","Title","Description..." )
    -->
    </script>

    Anybody have a clue what's going on here?

    TIA

    Brian Phelps
    Web Manager
    www.pacific.edu
    Last edited by btphelps; Oct 20, 2005 at 23:51.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You gave an incorrect URL. You meant http://iiswebdev.pacific.edu/default.asp

    That is very odd.

    Why are you using JavaScript to do that anyway? You should do that with the ASP.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the corrected URL.

    Yea, I thought of using ASP, but I know how to write thie function in Javascript but not ASP -- yet. Looks like I might be figuring that out soon.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alert()'s are your friend for debugging.

    1) If nothing is displayed in FF and there are no errors what does that mean is happening in your code? What must be happening if the document.write() statements aren't executing? Will the document.write() statements always execute no matter what?

    2) Hopefully, now you'll have a general idea of what must be happening. So, to test if you are right. Put an alert() before the if statement and inside the if statement. Do both alert()'s execute?

    3) Now why is that happening? The if statement has two conditions, so one must be failing. Use alert()'s to display the three variables being tested. Do they look correct? To further narrow down what's going on, try alert()ing the one that looks wrong with spaces between it's pieces. Then, you'll know which piece is wrong.

    4) Go up higher in your code and find out where that piece is coming from. Use an alert() to output the relevant piece immediately after it is calculated. Now why is that happening? Look in a modern js book and see how you are supposed to obtain that info.


Bookmarks

Posting Permissions

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