Forum Moderators: open
I have the following code (posted below) that is almost there but not quite.
I want each link to change the src of the iframe. But right now my code doesn't seem to want to loop through the array, but only checks the first item in this array. Not sure if my syntax is wrong?
The first link works if you want an example. The second will return negative when I think it should work.
cheers for any advice :-)
<title>Frame Tester</title>
<script type="text/javascript">
function scoreBoard(name, location) {
this.name = name;
this.location = location;
}
var scoreURL = new Array();
scoreURL[0] = new scoreBoard("live", "http://www.news.com.au");
scoreURL[1] = new scoreBoard("golf", "http://www.webmonkey.com");
scoreURL[2] = new scoreBoard("union", "http://www.csscreator.com");
function changeFrame(id) {
for (var i in scoreURL) {
if (scoreURL[i].name == id) {
document.getElementById('score-board').src = scoreURL[i].location;
break;
} else {
alert("no");
break;
}
}
}
</script>
</head>
<body>
<ul>
<li><a href="#" onclick="changeFrame('live');">Live</a></li>
<li><a href="#" onclick="changeFrame('golf');">Cricket</a></li>
<li><a href="#" onclick="changeFrame('union');">Football</a></li>
<li><a href="#" onclick="changeFrame('live');">NBL</a></li>
<li><a href="#" onclick="changeFrame('me');">NRL</a></li>
</ul>
<iframe id="score-board" src="http://www.google.com"></iframe>
</body>
</html>