This is all fine but it only works for the first name. I could probably resolve this by prompting for the first and last names seperately and then repeating the above code but that's not exactly what I want. I want it to only prompt once and capitalize their first name, middle name or last name, etc.

I did a bit of research and the toTitleCase() function kept on popping up, but I don't know if that's an actual function for JavaScript - Or is it? :confused:

Sure. However, doing it the way I have outlined is one of the most standards compliant methods available. Why is that a problem? It achieves basically the same result as document.write (which is not recommended), and results in code that can be reused after the page has loaded. Code that uses document.write can never be run after page load in modern browsers without obliterating the existing page.

Anyways, as I say, yes. What exactly did you have in mind?

Tseng

11-14-2008, 03:50 PM

It's just that this program is for a school project and I need to be able to explain it to my teacher, plus I also need to be able to play around with the program myself to figure it out and know what I'm doing. :) I would prefer the document.write method as that's the only one we've been taught at the moment. Additionally, the program won't be reused on the page so it will not be a problem using document.write.

Thank you for the help so far! :D

jscheuer1

11-14-2008, 04:54 PM

Since it is for school, I'm not going to tell you exactly what to do. I will tell you that:

So if you are skipping the bold part, you won't need the receiving element. And that:

test.join(' ');

in the code there returns the results you are looking for in string form.

I will mention too that, if you are using document.write, you cannot run the code onload as shown in my example. Also that your teacher is getting you off on the wrong foot by even mentioning document.write.

Maybe you should research nodeValue and any other terms you don't understand (these are all easily found using Google) and surprise your teacher by knowing what it means.

Tseng

11-14-2008, 08:20 PM

For some reason or another, it keeps returning it with a "," inbetween the words. I cannot figure out why it's doing this... :( I'd be really grateful if you could resolve this minor problem. :)

in the code there returns the results you are looking for in string form.

so:

document.write(test.join(' '));

BTW, good job on adapting the rest of it. But you really should place it in the body of the page, and:

language = "JavaScript"

is deprecated, it should be:

type="text/javascript"

Tseng

11-14-2008, 10:53 PM

It is working perfectly now :)

jscheuer1

11-14-2008, 11:28 PM

Where a script goes depends upon what it does, and how it does it. Many can go anywhere, in which case the preferred placement is in the head. However, if you are writing to the document body, at least the part that does that should go in the body, though most browsers (on a simple page with no other markup) will error correct for that if you get it wrong.

My comments on the language attribute being deprecated in favor of the type attribute are in accordance with the current W3C (accepted authority on these matters) recommendations, which you can look up on their site:

http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1

This basically means that to be valid HTML, a script tag must not use the language attribute and must use the type attribute.

jscheuer1

11-14-2008, 11:39 PM

I might add that the W3C sets the rules that browser manufacturers agree to support. It does not mean that many browsers will not also support other conventions, just that they are not required to. At this writing all major browser manufacturers have pledged to do their best to follow these recommendations, including Microsoft (who in the recent past had been one of the biggest wild cards in all this, though other manufacturers have fallen short at other times).

The bottom line is that by having everyone follow a set list of guidelines, it makes it easier to write code for all browsers without having to test in every browser.