/    Sign up×
Community /Pin to ProfileBookmark

Random Generator not generating anything …. why?

I’m new to javascript, I’ve always just taken free scripts from a variety of sources. This one’s sort of similar except that I took a random title generator script and have edited (or tried to edit) it to my needs.

I have no idea what is wrong and I’m not getting an error message – the random titles just simply aren’t showing up in the text fields when I click ‘Conjure Titles’. I don’t have a debugger or anything that could help me find the problem.

Basically, I can’t pin point what I need help with for you. If you want to see my code not working, go [URL=http://devoted2hp.webspace4free.biz/random.html]here[/URL].

Here the’s script below, can anyone tell me what’s wrong and how to fix it? I’ve chopped most of the words out of the array sections so the script isn’t that long for you to look at.

[code=php]<HEAD>
<script language=”JavaScript”>
<!–

var noun = new Array(
“Return”,”Legacy”,”Birth”,”Healer”,”Healing”,
“Wand”,”Spell”,”Full Body Bind”,”Jelly Legs Jinx”,
“Bat Bogey Curse”,”Common Room”,”Secret Passage”,”Decedant”
)

var name = new Array(
“Black”,”Malfoy”,”Buckbeak”,”Mrs Norris”,
“Lovegood”,”Luna”,”Cedric”,”Hufflepuff”,
“Cornelius”,”Ginny”,”Fred”,”Peter”,
“George”,”Molly”,”Doris Crockford”,”Potter”,
“Colin Creevey”,”Avery”,”Mr Ollivander”,”Bill”,
“Pig”,”Hermes”,”Phineas”,”Mrs Black”,
“Dobby”,”Winky”,”House Elf”,”Firenze”
)

var adjective = new Array(
“Metallic”,”Marble”,”Stony”,”Rocky”,”Great”,”Royal”,
“Noble”,”Wet”,”Dry”,”Bleeding”,”Piercing”,”Singing”,
“Dancing”,”Painful”,”Wandering”,”Loyal”,”Trusting”,
“Open”,”Closed”,”Locked”,”Free”,”Chained”,”Caged”,
“Empty”,”Wilted”,”Lunar”,”Solar”,”Screaming”,”Dead”,
“Shaking”,”Thrusting”,”Frantic”
)

var a = 0;
var b = 0;
var c = 0;
function RandomTitle(nameform) {
a = Math.floor(Math.random() * noun.length);
b = Math.floor(Math.random() * adjective.length);
c = Math.floor(Math.random() * name.length);
nameform.first.value=name[c] + “‘s ” + adjective[b] + ” ” + noun[a];
}

var d = 0;
var e = 0;
function RandomTitle2(nameform) {
d = Math.floor(Math.random() * adjective.length);
e = Math.floor(Math.random() * noun.length);
nameform.second.value=”The ” + adjective[d] + ” ” + noun[e];
}

var f = 0;
var g = 0;
function RandomTitle3(nameform) {
f = Math.floor(Math.random() * noun.length);
g = Math.floor(Math.random() * noun.length);
nameform.third.value=noun[f] + ” of ” + noun[g] ;
}

var h = 0;
var i = 0;
function RandomTitle4(nameform) {
h = Math.floor(Math.random() * noun.length);
i = Math.floor(Math.random() * name.length);
nameform.fourth.value=”The ” + noun[h] + “of ” + name[i];
}

var j = 0;
var k = 0;
function RandomTitle5(nameform) {
j = Math.floor(Math.random() * noun.length);
k = Math.floor(Math.random() * noun.length);
nameform.fifth.value=”Harry Potter and the ” + noun[j] + ” of the ” + noun[k];
}

var l = 0;
var m = 0;
var n = 0;
function RandomTitle6(nameform) {
l = Math.floor(Math.random() * noun.length);
m = Math.floor(Math.random() * noun.length);
n = Math.floor(Math.random() * name.length);
nameform.sixth.value=name[n] and the ” + noun[l] + ” of the ” + noun[m];
}

//–>
</script>
</HEAD>

<BODY>
<center>
<form>
<table width=400>
<tr>
<td align=center colspan=2>

<input type=button name=generate value=”Conjure Titles!” onClick=”RandomTitle(this.form);
RandomTitle2(this.form);RandomTitle3(this.form);RandomTitle4(this.form);RandomTitle5(this.form);RandomTitle6(this.form)”>
</td>
</tr>
<tr>
<td align=center><b>Title 1:</b></td>
<td align=center><input type=text name=first size=35
style=”background:white”></td>
</tr>
<tr>
<td align=center><b>Title 2:</b></td>
<td align=center><input type=text name=second size=35
style=”background:white”></td>
</tr>
<tr>
<td align=center><b>Title 3:</b></td>
<td align=center><input type=text name=third size=35
style=”background:white”></td>
</tr>
<tr>
<td align=center><b>Title 4:</b></td>
<td align=center><input type=text name=fourth size=35
style=”background:white”></td>
</tr>
<tr>
<td align=center><b>Title 5:</b></td>
<td align=center><input type=text name=fifth size=35
style=”background:white”></td>
</tr>
<tr>
<td align=center><b>Title 6:</b></td>
<td align=center><input type=text name=sixth size=35
style=”background:white”></td>
</tr>
</table>
</form>
</center>

</body>
[/code]

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

Please have a look at the very last line of your script (above the closing bracket):
[code=php]
nameform.sixth.value=name[n] and the " + noun[l] + " of the " + noun[m];
[/code]

it is missing a +". Try this:
[code=php]
nameform.sixth.value=name[n]+" and the " + noun[l] + " of the " + noun[m];
[/code]

Cheers - Pit
Copy linkTweet thisAlerts:
@AmethystMoonauthorDec 19.2003 — Oh wow! It works! Thank you soooo much! I am eternally grateful, hehehe! It works like a charm, THANK YOU!
Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

You're welcome and I am glad if I could help (by just pressing two keys :p)

Cheers - Pit
Copy linkTweet thisAlerts:
@AmethystMoonauthorDec 19.2003 — [i]Originally posted by Pittimann [/i]

[B]You're welcome and I am glad if I could help (by just pressing two keys :p)

[/B]
[/QUOTE]

Aww now don't I feel stupid :o

Hey, do you know if there's a free something-or-other I could download from anywhere that would pick up where I had missed out bits of coding (like that example) and tell me which line or something? Because (as you can see) I find it difficult spotting little glitches like that.

I know there's html ones around, where it makes sure you've closed and your tags etc - happen to know of a javascript one?

If there isn't a free one, do you recommend a program (that preferably would do html, javascript, css and maybe a few other languages) that I could ask my dear parents to buy for me?
Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

Depending on the browser you use, you might not need a special program to find bugs like that in your js.

I've heard (but I'm not sure!) that Netscape 7 has a built in feature for that; in IE you can simply check a checkbox for that. (internet options, advanced tab, display script errors - I do not really know how that will look like; my IE speaks German - anyway it should be something like that). In IE you would then get a message telling you a line number and (depending on the error, maybe) a short description of the error.

Please note, that, if you use external js files, the line number would be "wrong"...

Cheers - Pit

BTW - don't feel stupid! ?
Copy linkTweet thisAlerts:
@KorDec 19.2003 — Yes, NS6 and NS7 have that detailed error analyser at

Tools - Web Development - JavaScript Console

Even NS4.x has something similar. Just tape

[b]javascript:[/b]

in address space
Copy linkTweet thisAlerts:
@AmethystMoonauthorDec 19.2003 — [i]Originally posted by Pittimann [/i]

[B] in IE you can simply check a checkbox for that. (internet options, advanced tab, display script errors)[/B][/QUOTE]

I've done that but I'm not ure what to expect now. Is a popup box supposed to tell me all the script errors on each page I go to, or is there a directory or file on my computer where it lists the script errors and I have to go and find it?

Because my Random Generator stopped working again *ducks flying vegetables* LOL. I added more variables (I think that's the word) to the arrays and like it was before, nothing happens when I click the 'conjure titles' button. I've checked, corrected and re-checked all the commas and quotation marks but I can't find what's wrong. So something that can point out the location of the error would be wonderful.
Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

This IE thing just makes a message pop up indicating the line number and (most of the times) a short discription of the error. If there is more than one recognised error, a new message will pop up when clicking ok, indicating the next error.

It will not always tell you what the mistake actually is. E. g., if you have a missing "(" you might be alerted something like "expecting ';' on line x, char y". Or - if you miss a single "}" that might be interpreted as a missing "}" at the very end of the script.

At least, you will get a hint, that there's something wrong and if you have this option checked anytime you're surfing, you'll be surprised, with how many mistakes the net is crowded.

BTW - the errors are not logged in a file afaik...

To Kor: Thanks very much for your information!

Cheers - Pit
Copy linkTweet thisAlerts:
@AmethystMoonauthorDec 19.2003 — Ok, I'm not getting pop up messages but I did manage to open a Microsoft Script Editor by turning the 'display script errors' option on, opening the page with my generator on it and going 'View' -> 'Script Debugger' -> 'Open'.

Now I have a program open with the coding of my page (coloured) but I have no idea how to use this program or locate the error. Any help? *smiles sweetly*

Thanks by the way, for everything you've done so far! I really appreciate everything.
Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

Sorry - my IE doesn't have that feature (maybe bcause I'm running outdated Win 98). For the recent problem (if you don't mind) just post the altered code and I'll check it for you...

Cheers - Pit
Copy linkTweet thisAlerts:
@AmethystMoonauthorDec 19.2003 — [i]Originally posted by Pittimann [/i]

[B]Sorry - my IE doesn't have that feature (maybe bcause I'm running outdated Win 98). For the recent problem (if you don't mind) just post the altered code and I'll check it for you... [/B][/QUOTE]

I managed to get the program to tell me the problem area (or at least I think I did.) It said there was JScript runtime error: object expected in this bit of code:

[code=php]<input type="button" name="generate" value="Conjure Titles!" onClick="RandomTitle(this.form);
RandomTitle2(this.form);RandomTitle3(this.form);RandomTitle4(this.form);RandomTitle5(this.form);RandomTitle6(this.form)"
style="font-family:VERDANA"
style="border style:solid"
style="background:770099"
style="color:FF99FF">[/code]


When I get this working right, I'm going to put a 'thanks to Pittimann' at the bottom of the page. Couldn't have done this without your help!
Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

In the code you posted, there is a linebreak after:

<input type="button" name="generate" value="Conjure Titles!" onClick="RandomTitle(this.form);

Please remove it. I think, that already will eliminate the problem, but please make sure, there is a space between:

'onClick="RandomTitle(this.form);' and 'RandomTitle2(this.form);etc.'...

BTW - the linebreaks in your style stuff do not disturb in this case, but did you know you can put the style attributes all in one style="x1:y1;x2:y2;ect.;" (just separating the attributes with ";"?

Cheers - Pit

P.S. object expected could probably mean, that you didn't test that <input ....> in a document containing the script. Clicking the button will call the function(s), but the script is not there.
Copy linkTweet thisAlerts:
@AmethystMoonauthorDec 19.2003 — I've done that and it still won't work. Since I can't find what the problem is, I think I might start from scratch. After all it only took a few hours the first time round so the re-doing (only hopefully not re-doing the mistake!?) should take about an hour.

Thanks for all your help, you're wonderful! If you want to see the page or 'view source' I posted a link in my very first post in this thread.

And as for the style - no I didn't know that. Thanks ? Love learning new shortcuts!

Lily
Copy linkTweet thisAlerts:
@KorDec 19.2003 — [b]object expected[/b] occures even when you forgot to end with : or with } or you misspell the names, or... a lot of causes, which, as well Pittimann said, "distroy" the function or the integrity of the script and/or the HTML code lines
Copy linkTweet thisAlerts:
@PittimannDec 19.2003 — Hi!

It took me a while to get it, because I simply ignored the fact, that you a window.onerror line in your script.

Well - two tiny typos remain. If you "repair" them, everything will work. Both are in your noun Array: line 57 - missing double quote before 'Red Cap' and line 82 - no comma at the end of the line.

BTW - I would be glad, if you just linked to these forums (if you like and insist), but my name is of no relevance on your page... :p

Cheers - Pit
×

Success!

Help @AmethystMoon 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...