...

View Full Version : Using document.getElementById to open website



luigicannavaro
10-02-2008, 10:27 PM
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

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

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

<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

abduraooft
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

document.getElementById('mylink').href='http://mydomain.com/nameofmypage.htm';

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum