Javascript help?

The code on this page is almost perfect for my purposes…but in adapting it and previewing, I’ve discovered that the box isn’t big enough. A few of my word choices run off to the end with just two long words, and I’d like to have a phrase in one version.

What do I need to do to make the box bigger?

I’m going to assume that the size is found within this:

function BuildArray(size){
this.length = size
for (var i = 1; i <= size; i++){
this* = null}
return this

But I don’t understand what the code indicates since I was expecting px or something there. How do I adjust it to have the width be 100 characters?

You assumed wrongly. That code is talking about building the array of words to select randomly from.

To control the size of the display text box you need to add attributes to the html which defines the text box itself:


The bold part is the size of the text box measured in typical characters at the page’s default font sixe. Change the 10 to 20 or something.

You could also add a style attribute to your input element, e.g.

<INPUT TYPE=TEXT SIZE=10 NAME="WordBox" style="width:200px;">

Thanks, that worked :slight_smile:

Unfortunately, for some reason I can’t get anything to happen when you click the buttons if I put more than one on the same page. The idea was to have three on the same page, so I’ll probably use a different script after all…

Programming by pasting stuff you don’t understand is not a good way to build anything.

The problem you’ve got now is the javascript is coded to always update a single textbox referred to by name. So if you leave the js as-is & create 3 text boxes & 3 buttons, each button updates the first textbox only.

The solution is for you to learn enough about html & js to be able to understand what it’s doing and why, and then how to modify it accordingly. The best way to do that is not through blind tinkering, nor through more exercises of searching, cutting and pasting, and guessing.

A good book or online tutorial will get you going in the right direction with just a couple day’s worth of effort. You’ll be amazed at how even a little skill opens up your possibilities.

This is one of Douglas Cockford’s big complaints about Javascript: That it has a reputation for being a tinkerer’s language, so no one really bothers to learn it fully. While it has a lot of aspects that are clunky and stupid, it also has a bunch of features (first class functions, closures, &c) that were really ahead of its time but they don’t get used to their fullest extent because the language is not really taken seriously.