Results 1 to 4 of 4

Thread: combining an if statement with other javascript

  1. #1
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default combining an if statement with other javascript

    Hi, Hope someone can help and indeed if it can be done.

    I need to combine this if javascript

    Code:
    <script type="text/javascript">
    var d = new Date()
    var time = d.getHours()
    if (time<10)
    {
    document.write("<b>Good morning</b>")
    }
    else if (time>=10 && time<11)
    {
    document.write("<b>Good day</b>")
    }
    else
    {
    document.write("<b>Hello World!</b>")
    }
    </script>

    with this.

    Code:
    <a onmouseover="doTooltip(event,'<img src=&quot;<%=Server.URLPathEncode(rsCard("ThumbnailURL"))%>&quot;>
    
    <div class=&quot;tp2&quot;><%If Trim(rsCard("Author"))<>"" Then%> <%=rsCard("Author")%><%End If%></div>' )" onmouseout="hideTip()" href="http://xxxxxxx">xxxxxxx</a></font>
    I basically need the onmouseover event which has an asp include to display a different image at different times. I have three asp includes ABC so I am imagining something along the lines of.

    Code:
    document.write("<a onmouseover="doTooltip(event,'<img src=&quot;<%=Server.URLPathEncode(rsCard("ThumbnailAURL"))%>&quot;>")
    }
    else if (time>=10 && time<16)
    {
    document.write("<a onmouseover="doTooltip(event,'<img src=&quot;<%=Server.URLPathEncode(rsCard("ThumbnailBURL"))%>&quot;>")
    }
    else
    {
    document.write("<a onmouseover="doTooltip(event,'<img src=&quot;<%=Server.URLPathEncode(rsCard("ThumbnailCURL"))%>&quot;>")
    }
    I know thats completely wrong, but hope someone gets the idea. It of course needs to include the rest of the code.
    Any help would be appreciated.
    Thanks
    Richard

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    ASP, PHP, and any other server side code is processed at the time the page is served; there is no ASP, etc. left in th source, in fact. So this means, in terms of javascript, it's just like having the url typed directly there, assuming it is in fact output correctly by the ASP.

    The simple answer is to use a function.

    function name() {
    ...
    }

    call name() in the onMouseover, and then place the if statements in the function (which would go in the script tags, not in the onmouseover attribute).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Daniel, Thanks for the quick reply. It makes sence. I will try and do what you suggest.
    Thanks again
    Richard

  4. #4
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Quote Originally Posted by rich1234
    else if (time>=10 && time<11)
    I would like to point out that time is an integer (due to getHours()), so you could and should write the above snippet as
    Code:
    else if(time==10)
    Trinithis

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
  •