/    Sign up×
Community /Pin to ProfileBookmark

Need to relate random content to specific content

Hi guys, I’m a real amateur. I’m just a lawyer with a blog

iusandlaw.blogspot.com

I’ve been able to change it a little bit with the help of mighty google. But now I reached my limits: I want to do something I just can’t do.

I have a random header image installed. And I have navigation bar, very amateur, which is actually the creation of the template creator Gecko&Fly.

Here’s the script of the random image.

<script type=’text/javascript’>

var banner= new Array()

banner[0]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.jpg&quot;[/url]
banner[1]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.1.jpg&quot;[/url]
banner[2]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.2.jpg&quot;[/url]
banner[3]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.3.jpg&quot;[/url]
banner[4]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.4.jpg&quot;[/url]
banner[5]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.5.jpg&quot;[/url]
banner[6]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.6.jpg&quot;[/url]
banner[7]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.7.jpg&quot;[/url]
banner[8]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.8.jpg&quot;[/url]
banner[9]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.9.jpg&quot;[/url]
banner[10]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.10.jpg&quot;[/url]
banner[11]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.11.jpg&quot;[/url]
banner[12]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.12.jpg&quot;[/url]
banner[13]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.13.jpg&quot;[/url]
banner[14]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.14.jpg&quot;[/url]
banner[15]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.15.jpg&quot;[/url]
banner[16]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.16.jpg&quot;[/url]
banner[17]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.17.jpg&quot;[/url]
banner[18]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.18.jpg&quot;[/url]
banner[19]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.19.jpg&quot;[/url]
banner[20]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.20.jpg&quot;[/url]
banner[21]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.21.jpg&quot;[/url]
banner[22]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.22.jpg&quot;[/url]
banner[23]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.23.jpg&quot;[/url]
banner[24]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.24.jpg&quot;[/url]
banner[25]=&quot;[url]http://photos1.blogger.com/blogger/2915/509/1600/pic.25.jpg&quot;[/url]

var random=Math.round(25*Math.random());

document.write(&quot;<style>&quot?;
document.write(&quot;#headr {&quot?;
document.write(‘ background:url(&quot;’ + banner[random] + ‘&quot? no-repeat left TOP;’);
document.write(&quot; }&quot?;
document.write(&quot;</style>&quot?;

</script>

And here’s the relevant part of the “supernav” (navigationbar)

#supernav {
font: bold 12px/12px Impact, Verdana, Lucida Grande, Arial, Sans-Serif;
position: absolute;
top: 181px;
left: 50%;
width: 720px;
margin: 0 0 0 -360px;
padding: 5px 16px; /* duplicate the tab size */
text-align: left;
display: block;
}

#supernav li {
margin: 0;
padding: 0;
text-transform: lowercase;
display: inline;
}

#supernav a {
color: #000000;
background: #FFFFFF;
font-weight: normal;
height: 19px;
padding: 5px 16px;
/* round corner tab – not for IE */
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
}

#supernav a:hover {
text-decoration: underline;
}

#supernav .current_page_item a {
color: #111;
background: #999;
text-decoration: none;
/* round corner tab – not for IE */
-moz-border-radius-topright: 6px;
-moz-border-radius-topleft: 6px;
}

(and later on…)

<ul id=’supernav’>
<li><a href=’http://iusandlaw.blogspot.com’>Home</a></li>

<li><a href=’http://iusandlaw.blogspot.com/2005/05/este-blog-naci-el-4-de-mayo-de-2005-por.html’>Sobre el autor</a></li>
<li><a href=’http://iusandlaw.blogspot.com/search/label/Arte’>arte, arte, arte!</a></li>
<li><a href=’http://iusandlaw.blogspot.com/search/label/Viaje’>Crónicas Europeas</a></li>
<li><a href=’http://www.flickr.com/photos/raxphotos/sets/72157594159366227/’>Flickr Set</a></li>

</ul>

(I think is a wdiget in new blogger beta).

PLaying with the nav html, I’ve managed to duplicate it and I put it hight on the header, as you can see in my blog: [URL=”http://iusandlaw.blogspot.com”]iusandlaw.blogspot.com[/URL].

(It’s just a black rectangle up and to the right over the header).

What I want to do is to relate every image that appears to specific text and a link that would have to appear every time the image changes. Basically, what I want to do is to say where the picture was taken. If it can link to a specific google maps link, that would be greate.

Any ideas? I’ve tried de If (function) thing, but coudn’t do it. Hope someone can help! Best,

R.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@cyber1Jun 23.2008 — Try this:

I have shortened your quotes array and added a second array which uses the same random 'index' value
[code=html]
<script language="JavaScript">
//store the quotations in arrays
quotes = new Array(5);
quotes[0] = "Un sabor eterno se nos ha prometido, y el alma lo recuerda. Leopoldo Marechal.";
quotes[1] = "No hay Revolución sin Revolucionarios - Los revolucionarios de todo el mundo somos hermanos. José de San Martín.";
quotes[2] = "El obrero tiene más necesidad de respeto que de pan. Karl Marx.";
quotes[3] = "Cuando alimenté a los pobres me llamaron santo; pero cuando pregunté por qué hay gente pobre me llamaron comunista. Obispo Helder Camara.";
quotes[4] = "Tendremos que arrepentirnos en esta generación, no tanto de las malas acciones de la gente perversa, sino del pasmoso silencio de la gente buena. Martin Luther King.";

//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("n");
document.write(quotes[index]);

var links= new Array();
links[0]='<a href="http://google.com">GOOGLE</a>'
links[1]='<a href="http://msn.com">MSN1</a>'
links[2]='<a href="http://msn.com">MSN2</a>'
links[3]='<a href="http://msn.com">MSN3</a>'
links[4]='<a href="http://msn.com">MSN4</a>'
document.getElementById("piclink").innerHTML = links[index]

</script>[/code]



then change the link to a span:
[code=html]<ul id='supernav2'>
<li><span id="piclink"></span></li>
</ul>
[/code]
Copy linkTweet thisAlerts:
@abogadoamateurauthorJun 27.2008 — I've tried to do it, but couldn't hack it. Probably my bad.

Either way, I don't want to relate my random quotes with specific links, but my pictures of the header to specific links.

BTW: where I'm supposed to put the last part, that's

...

<ul id='supernav2'> <li><span id="piclink"></span></li> </ul>


---

Tank 4 your help!
Copy linkTweet thisAlerts:
@cyber1Jun 28.2008 — Try the attached file.

It was too large to upload so I deleted everything after the last '</script>' close tag as it was in your original file.

Basically what I did was combine all the JS into one script and moved it further down the page. Then added elements to the banners array for the description and url.

[upl-file uuid=13d211b9-802a-4861-ae11-18710f8e37d2 size=18kB]test_testarray.txt[/upl-file]
Copy linkTweet thisAlerts:
@abogadoamateurauthorJun 28.2008 — Hi cyber1.

Thanks for your help. Your post made understand a few things about Java.

I hack it a few hours ago with a "if" function. Check out the script (it's in the HTML template, not a widget).

<script type='text/javascript'>

var banner= new Array(25)

banner[0]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.jpg&quot;

banner[1]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.1.jpg&quot;

banner[2]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.2.jpg&quot;

banner[3]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.3.jpg&quot;

banner[4]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.4.jpg&quot;

banner[5]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.5.jpg&quot;

banner[6]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.6.jpg&quot;

banner[7]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.7.jpg&quot;

banner[8]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.8.jpg&quot;

banner[9]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.9.jpg&quot;

banner[10]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.10.jpg&quot;

banner[11]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.11.jpg&quot;

banner[12]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.12.jpg&quot;

banner[13]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.13.jpg&quot;

banner[14]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.14.jpg&quot;

banner[15]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.15.jpg&quot;

banner[16]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.16.jpg&quot;

banner[17]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.17.jpg&quot;

banner[18]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.18.jpg&quot;

banner[19]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.19.jpg&quot;

banner[20]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.20.jpg&quot;

banner[21]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.21.jpg&quot;

banner[22]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.22.jpg&quot;

banner[23]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.23.jpg&quot;

banner[24]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.24.jpg&quot;

banner[25]=&quot;http://photos1.blogger.com/blogger/2915/509/1600/pic.25.jpg&quot;

var random=Math.round(25*Math.random());

document.write(&quot;<style>&quot?;

document.write(&quot;#headr {&quot?;

document.write(&#39; background:url(&quot;&#39; + banner[random] + &#39;&quot? no-repeat left TOP;&#39?;

document.write(&quot; }&quot?;

document.write(&quot;</style>&quot?;

//THIS IS WHAT I ADD -->

function male() {

if (random == 1) return(&#39;Trenes de Berlin&#39?;

if (random == 2) return(&#39;Barcelona, cerca de la Rambla&#39?;

if (random == 3) return(&#39;Museo del Louvre, Paris&#39?;

if (random == 4) return(&#39;Centro Casas Viejas, Sevilla&#39?;

if (random == 5) return(&#39;La Pedrera, Barcelona&#39?;

if (random == 6) return(&#39;Barcelona&#39?;

if (random == 7) return(&#39;Paris&#39?;

if (random == 8) return(&#39;La Place des Volges&#39?;

if (random == 9) return(&#39;Paris&#39?;

if (random == 10) return(&#39;Berlin Hauptbahnhof&#39?;

if (random == 11) return(&#39;Berlin&#39?;

if (random == 12) return(&#39;Brujas&#39?;

if (random == 13) return(&#39;Volendam, Holanda&#39?;

if (random == 14) return(&#39;Amsterdam&#39?;

if (random == 15) return(&#39;Amsterdam&#39?;

if (random == 16) return(&#39;Sony Center, Berlin&#39?;

if (random == 17) return(&#39;El Muro&#39?;

if (random == 18) return(&#39;Reichstag, Berlin&#39?;

if (random == 19) return(&#39;Potsdamer Platz&#39?;

if (random == 20) return(&#39;Tacheles, Berlin&#39?;

if (random == 21) return(&#39;Universidad Jagellónica, Cracovia&#39?;

if (random == 22) return(&#39;Cracovia&#39?;

if (random == 23) return(&#39;Castillo de Praga&#39?;

if (random == 24) return(&#39;Praga&#39?;

if (random == 25) return(&#39;Puente de Carlos&#39?;

}


//--&gt;</script>

Now, every time the random numbers 'select' a banner / header, the same number selects specific content. And so it relates every picture to the place where the picture was taken.

Finally, I've managed to put that content in the box I've prepared ('supernav2', to the top right of the header, little black box) with a little piece of script:

<ul id='supernav2'>

<li><a> <script>document.write(male())</script></a>

</li></ul>

I got one doubt though. I can't seem to be able to put a link on the content that every random number 'returns'. If I try to put html there, the hole thing stops working. For example, I want that when the random number is one (a pciture of Berlin train -- > content is 'Trains of Berlin') I want to be able to click on 'Train of Berlin' and be able to go to google maps location, for example. But I can't seem to be able to put HTML there. Any idea?

Thanks a lot! I think I'm learning something here, gonna buy myself some HTML and JAVA book or something.

Cheers.
Copy linkTweet thisAlerts:
@cyber1Jun 28.2008 — abogadoamateur-
Hi cyber1.

Thanks for your help. Your post made understand a few things about Java.[/QUOTE]

To clarify there is a difference between Java and Javascript. So you may want to google for the differences.



I hack it a few hours ago with a "if" function. Check out the script (it's in the HTML template, not a widget).

[/QUOTE]


Thats why I suggested using the array as the 'if' routine is very inefficient.


Now, every time the random numbers 'select' a banner / header, the same number selects specific content. And so it relates every picture to the place where the picture was taken.

Finally, I've managed to put that content in the box I've prepared ('supernav2', to the top right of the header, little black box) with a little piece of script:

<ul id='supernav2'>

<li><a> <script>document.write(male())</script></a>

</li></ul>

I got one doubt though. I can't seem to be able to put a link on the content that every random number 'returns'. If I try to put html there, the hole thing stops working. For example, I want that when the random number is one (a pciture of Berlin train -- > content is 'Trains of Berlin') I want to be able to click on 'Train of Berlin' and be able to go to google maps location, for example. But I can't seem to be able to put HTML there. Any idea?

Thanks a lot! I think I'm learning something here, gonna buy myself some HTML and JAVA book or something.

Cheers.[/QUOTE]


Have you tried what I posted as it does this all in one array and one script?

banner[0]="http://photos1.blogger.com/blogger/2915/509/1600/pic.jpg|Trenes de Berlin|http://linktopic1"

banner[1]="http://photos1.blogger.com/blogger/2915/509/1600/pic.1.jpg|Barcelona, cerca de la Rambla|http://linktopic2"
Copy linkTweet thisAlerts:
@abogadoamateurauthorJun 28.2008 — Gonna try it right now. Thanks!
Copy linkTweet thisAlerts:
@Declan1991Jun 28.2008 — If the pictures are numbered pic, pic1, pic2, ..., pic25, this might be a little easier to maintain.
<i>
</i>var banner = ["http://photos1.blogger.com/photoInclude/blogger/2915/509/1600/pic.jpg"];
var i = 26;
while (--i) {
banner[banner.length] = "http://photos1.blogger.com/photoInclude/blogger/2915/509/1600/"+i+".jpg";
}
var places = ['Trenes de Berlin','Barcelona, cerca de la Rambla','Museo del Louvre, Paris','Centro Casas Viejas, Sevilla','La Pedrera, Barcelona','Barcelona','Paris','La Place des Volges','Paris','Berlin Hauptbahnhof','Berlin','Brujas','Volendam, Holanda','Amsterdam','Amsterdam','Sony Center, Berlin','El Muro','Reichstag, Berlin','Potsdamer Platz','Tacheles, Berlin','Universidad Jagell&amp;#243;nica, Cracovia','Cracovia','Castillo de Praga','Praga','Puente de Carlos'];
// [] is just another way of writing new Array();
var lls = [];
lls[0] = "lat,lon";
// Example
lls[1] = "30.088108,-84.550781";
// etc.
var random=Math.round(25*Math.random());
document.write("&lt;style&gt;#headr {background:url("+banner[random]+" no-repeat left TOP; }&lt;/style&gt;");
function link() {
document.write('&lt;a href="http://maps.google.com/?ie=UTF8&amp;ll='+lls[random]+'&amp;z=15"&gt;'+places[random]+'&lt;/a&gt;');
}&lt;/script&gt;

&lt;ul id='supernav2'&gt;
&lt;li&gt;&lt;a&gt; &lt;script&gt;document.write(link())&lt;/script&gt;&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;
Be sure you remember the difference between JavaScript and Java, if you are going to buy a book. I'd also recommend the tutorials at w3schools.
×

Success!

Help @abogadoamateur spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...