Can you resolve this HTML and JavaScript problem?

Question by Ali: Can you resolve this HTML and JavaScript problem?
This is my whole HTML document:


function typename(){
name=prompt(‘What is your name?’,’Your name here’)
if(name==’null’){
document.write(“

You didn’t enter your name, so you will be redirected automatically to another page in seconds.

“)
}else{
nameparts=name.split(‘ ‘)
nameparts=nameparts.charAt(0).toUpperCase()+nameparts.substring(1,nameparts.length).toLowerCase()
name=nameparts.join(‘ ‘)
document.write(‘

Hello, ‘+name+’. Welcome to your page.

‘)
}}

Name

Please Enter Your Name Here:



I want this script to Capitalize each word’s first letter.
For example change “bill gates” to “Bill Gates”.
How can I do that?

Best answer:

Answer by Ck
it’s a css style, text-transform: capitalize;

so if your wanting to do it in the javascript you’ll need to write:

name.style.textTransform = ‘capitalize’;

What do you think? Answer below!

Add a Comment

Your email address will not be published. Required fields are marked *