style.setattribute and CSS capitalize

Hi - I'm trying to use"text-transform", 'capitalize');
and for whatever reason IE isn't liking it.  Is my syntax incorrect?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Can you use "'capitalize' instead?
function changeCase(caseType){
	var el = document.getElementById('test');
	if (caseType =='capitalize'){'capitalize';

	if (caseType =='uppercase'){'uppercase';

	if (caseType =='lowercase'){'lowercase';
	return false;
<div id="test">This is a test message</div><br/>
<a href="javascript:void(0)" onclick="javascript:changeCase('capitalize');return false">capitalize</a></br>
<a href="javascript:void(0)" onclick="javascript:changeCase('uppercase');">uppercase</a></br>
<a href="javascript:void(0)" onclick="javascript:changeCase('lowercase');">lowercase</a></br>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zack4x4Author Commented:
I'm dynamically adding inputs into a form I don't think that will work in this case.
this cannot possible work:"text-transform", 'capitalize');

style does not have a setAttribute method.

You can try:

inputE1.setattribute("style" "text-transform:capitalize",0);

The zero on the end is necessary to turn off IE case-sensitivity.

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Ooops a spelling mistake

setAttribute is the correct camel case spelling.

zack4x4Author Commented:
that didn't work. I tried with Firefox and IE
Sorry it took me awhile to get back to this.  CD& is correct on how you do it for elements that you are adding that are not yet in the DOM.  

Open in new window

Some thoughts on the cross-browser issues...

Testing locally,
It works for FF9, Chrome 16, and Safari 5.1.2
With IE8, it works with both IE8 compatibility and IE8 standards.  It does not work with IE7 or Quirks Mode.

Have you tried creating a style such as  ".initCaps {text-transform:capitalize} and adding it as a second class to the item?

Alternatively, have you tried adding the item you are creating to your DOM then running the code I posted?
Good idea nap.  When I do dynamic generation, I normally like it in the document object first.  Then modifying styles has very few cross-browser issues.  With forms you have to be careful anyway because it is easy to break them.


What version if IE are you testing with?  IE8 and 9 should both be able to handle it.  Anything older is probably irrelevant anyway.  

zack4x4Author Commented:
IE9.  For some reason when I click the add button to activate it nothing happens.  I don't get a javscript error either.  When I remove the line it starts working again...
Is the element being created correctly?  I should be something like:

inputE1.setAttribute("type", "text");

If nothing is working maybe we need to see more of the script.

Just as an FYI - here is the code I tested with:
	var firstName = document.createElement("input");

Open in new window

That should work, if nothing else is broken.

zack4x4Author Commented:
Thanks guys!  I split the points between you to.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.