This attaches a submit handler to form, so you don't need that inline onClick="sampleArray()" JS in your HTML markup. I've also outputted the contents of the array as a string each time, so you can see that the colours are being added.

Pullo
—
2014-01-06T20:13:51Z —
#3

Hi there,

Well, what is causing your immediate problem is the fact that the form is submitting, hence the results being only displayed briefly on the console.

You can normally solve this by passing a reference to the event that triggered the function to the function and preventing the browser's default action:

function someFunction(e) {
e.preventDefault();
...
}

However, you have attached a click handler to a button within the form and this is going to trigger the submit regardless.

... and there is a better way to do this:

Remove the inline click event handler and attach a submit event handler to the form unobtrusively:

fretburner, That code looks a bit advanced for my current stage, but thanks!

Pullo
—
2014-01-06T20:49:51Z —
#5

What are you having trouble with?The code I posted is only five lines long, so we could step through it if you like.

Edit:

Ok, you added the word "fretburner"

StevenHu
—
2014-01-10T19:06:42Z —
#6

The sample code works great! I just wasn't introduced to the e.preventDefault(); in the book yet, so your code threw me off. I have another question about this code, but I'll put it in another post because it's different.