473,410 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Choosing A Random Name Issues...

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

Aug 18 '08 #1
5 1319
There are two obvious errors in the code...

var new_window=window.open("","new_window," "height=100, width=100");

Should be ...

var new_window=window.open("","new_window", "height=100, width=100");

...and...

var message="I think the class feels that"+names[my_num]+should answer
the question";

Should be...

var message="I think the class feels that"+names[my_num]+"should
answer the question";

Jees, who writes this stuff?
Aug 18 '08 #2
Laser Lips wrote:
Thanks for your response.
>There are two obvious errors in the code...

var new_window=window.open("","new_window," "height=100, width=100");

Should be ...

var new_window=window.open("","new_window", "height=100, width=100");
where's the difference here?
>
var message="I think the class feels that"+names[my_num]+should answer
the question";

Should be...

var message="I think the class feels that"+names[my_num]+"should
answer the question";
okay, got it...another gramatical error...
>Jees, who writes this stuff?
--
Message posted via http://www.webmasterkb.com

Aug 18 '08 #3
>>There are two obvious errors in the code...
>>var new_window=window.open("","new_window," "height=100, width=100");
>>Should be ...
>>var new_window=window.open("","new_window", "height=100, width=100");
>where's the difference here?
Look again...

var new_window=window.open("","new_window," "height=100, width=100");

Should be ...

var new_window=window.open("","new_window", "height=100, width=100");

Aug 18 '08 #4
In comp.lang.javascript message <88d4ff5462bfe@uwe>, Mon, 18 Aug 2008
01:57:22, LayneMitch via WebmasterKB.com <u39402@uwe.?.invalidposted:
var ran_Num=parseInt(Math.random()*5);
Additionally, you should choose a better, more intelligent source to
copy from. Newsgroup FAQ 4.44 and link(s) refer.

Write less code at once, and test incrementally. Test with a browser
that displays at least reasonable error reporting - Firefox, Opera, for
example.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 18 '08 #5
Laser Lips wrote:
>
Look again...

var new_window=window.open("","new_window," "height=100, width=100");

Should be ...

var new_window=window.open("","new_window", "height=100, width=100");
Okay got that. And it's still not working. what the heck!?

All of the suggested updates have been made. Here's the new 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

Aug 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Weholt \( PRIVAT \) | last post by:
I've got a rather small project, small in the sense that there's not a lot of different tables needed in the database/storage-system, but there will be alot of data and the clients must be able to...
6
by: Acacia | last post by:
How would you generate a random number in C++?
1
by: Randall Parker | last post by:
Looking at the fields for configuring a web site's security and I'm using Forms authentication. Saw the part about assigning a cookie name. I assume this is the cookie that gets set when a person...
2
by: yay_frogs | last post by:
Here is my problem: suppose there are, say, five events with these probabilities: event1 0.7 event2 0.1 event3 0.1 event4 0.05 event5 0.05 Note that sum of the probabilities is...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
26
by: Jimmy | last post by:
ill have a database with 1 table and 3 fields: ID FIRSTNAME LASTNAME (the ID field will be the auto incrementing index) there might be 10 records in the DB, there might be 10,000. i...
19
by: hansBKK | last post by:
Upfront disclaimer - I am a relative newbie, just starting out learning about PHP, mostly by researching, installing and playing with different scripts. I am looking for a host that will provide...
11
by: alpha.beta0 | last post by:
I have a MySQL table of servers, I use RAND() to pick a random server to use each time, but how can I add a number to each server entry that allows it be to picked more often than the other 20...
36
by: Pat | last post by:
Hi, I've run into a strange problem, but one that seems like it might be fairly common. I have a single base class, from which several other classes are derived. To keep the example simple,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.