Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder luigicannavaro's Avatar
    Join Date
    Aug 2007
    Posts
    150
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Unhappy Using document.getElementById to open website

    Hi friends,

    I want to get a website using a script in this way:

    <script>
    document.getElementById("tcuerpo_a").src = "http://www.eldiario.net/noticias/nt" + year + "/tcuerpo_a.jpg";
    </script>
    What I must to do for output this image?

    Thank you in advance

    Luigi

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    What's this tcuerpo_a?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ID = tcuerdo_a .

    Now (yesterday at night) I did several changes in the script - all works fine - BUT I don´t how open DYNAMICALLY the link. Please, see my example and script:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <script type="text/javascript">


    function FormatNu(nu){
    return nu>9?nu:'0'+nu;
    }

    {
    var time=new Date();
    var lmonth=time.getMonth() + 1;
    var date=time.getDate();
    var year=time.getFullYear();
    //else year2=time.getYear();

    document.write("<center>" + year +"/"+ FormatNu(lmonth) + "/");
    document.write(FormatNu(date) + "</center>");

    }

    function changeSource()
    {

    var foo = (new Date().getFullYear()).toString();
    // Contains last two characters of the full year.
    // ex: 2003 evaluates to 03.
    var bar = foo.substring(foo.length, 2);
    //document.write(bar);

    document.getElementById("emerc").src = "http://diario.elmercurio.com/Fotos/" + year + "/" + FormatNu(lmonth) + "/" + FormatNu(date) + "/tcuerpo_a.jpg";
    document.getElementById("ediar").src = "http://www.eldiario.net/noticias/nt" + bar + FormatNu(lmonth) + FormatNu(date) + "/prima_a.jpg";
    }



    </script>

    </head>

    <body onload="changeSource()">

    <A HREF="????"> <IMG SRC="tcuerpo_a.jpg" id="emerc" WIDTH=120 HEIGHT=200><br>Mercurio</A><br><br>

    <A HREF="????"> <IMG SRC="prima_a.jpg" id="ediar" WIDTH=120 HEIGHT=200><br>Diario</A><br><br>

    <br><br>


    </body>
    </html>

    The script works fine, but I don´t know what to write here <A HREF="????"> to open the link dynamically every day with its respective date!

    Thank you in advance.

    luigi

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Hope you're trying to change/assign the href of an anchor. If so, assign an id to the link and then change the link by javascript, say
    Code:
    document.getElementById('mylink').href='http://mydomain.com/nameofmypage.htm';
    Code:
    <a href="#" id="mylink"><img src="...."/></a>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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