Code is suppose to choose a random name using 'event listeners'. The
reference file is a file downloaded from the book's publisher "Sitepoint". I
doubt that there is anything wrong with the file itself. There has to be
something wrong with the code or my referencing of the file (the file is in
the same directory as the code). Not sure, but here's the code:
<html><head><title>Prob.4</title>
<style type="text/css">
#textfield {position:absolute; left:0; top: 15;}
</style>
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript">
var RandomName=
{
init:function()
{
var form=document.getElementsByTagName("form")[0];
var my_button=form.firstChild;
Core.addEventListener(my_button,"click", RandomName.chooseNumber);
},
chooseNumber:function()
{
var ran_Num=parseInt(Math.random()*5);
RandomName.chooseName(ran_Num);
},
chooseName:function(my_num)
{
var names=new Array();
names[0]="Moe";
names[1]="Larry";
names[2]="Curly";
names[3]="James";
names[4]="John";
var new_window=window.open("","new_window," "height=100, width=100");
new_window.src=names[my_num];
var text_div=document.getElementById("textfield");
var message="I think the class feels that"+names[my_num]+should answer
the question";
text_div.innerHTML=message;
}
};
Core.start(RandomName);
</script></head>
<body>
<div id="textfield"></div>
<form>
<input type="button" value="Choose a name">
</form>
</body>
</html>
--
Message posted via http://www.webmasterkb.com