View Full Version : Using document.getElementById to open website

10-02-2008, 10:27 PM
Hi friends,

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

document.getElementById("tcuerpo_a").src = "http://www.eldiario.net/noticias/nt" + year + "/tcuerpo_a.jpg";

What I must to do for output this image?

Thank you in advance


10-03-2008, 03:35 AM
What's this tcuerpo_a?

10-03-2008, 12:14 PM
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">

<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.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";



<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>



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.


10-03-2008, 01:49 PM
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


<a href="#" id="mylink"><img src="...."/></a>