Results 1 to 3 of 3

Thread: Need coding to display if condition is true

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need coding to display if condition is true

    I have a webpage that utilizes the HTML tags <ul> and <li> to list links. Each link is for a different signup FORM.

    What I am looking for is a javascript command/code that will display this link as long as the condition is TRUE.

    I have the js code for the date and if statements below:

    <script type="text/javascript">
    <!--
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()
    if (month == 4 && day <= 30) {
    display href link here
    }
    //-->
    </script>

    The HTML code below is what I want to display as long as the IF condition is TRUE.
    <li>SIGNUP:&nbsp;<a href="webpage"><span style="color: rgb(0, 0, 255);">SIGNUP FORM FOR TESTING</span></a></li>

    ...where "webpage" = url for webpage

    Therefore, if the date is after April 30, this link would not display on website.

    I appreciate any help with this.

    Thanks,

  2. #2
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    If I understand correctly, you want it to write the code if the statement returns true. Right?

    If so, just add the document.write() to the script:
    Code:
    <script type="text/javascript">
    <!--
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()
    if (month == 4 && day <= 30) {
    document.write('<ul><li>SIGNUP:&nbsp;<a href="webpage"><span style="color: rgb(0, 0, 255);">SIGNUP FORM FOR TESTING</span></a></li></ul>');
    }
    else {
    return false
    }
    //-->
    </script>
    Hope that helps!

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  3. The Following User Says Thank You to X96 Web Design For This Useful Post:

    WLMPilot (04-16-2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Thanks

    Code worked great! Thanks for your help.

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
  •