Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert to Proper case 2

Status
Not open for further replies.

celticking

Technical User
Feb 15, 2001
69
US
I have one more problem i need help with. I have a form page with many fields. Is there a way, when this form is submitted to convert the fields to proper case?

Again, thanks for an help.
 
String.prototype.ucfirst = function()
{
var x, y;
x = this.substring(0, 1);
y = this.substring(1, this.length);
x = x.toUpperCase();
y = y.toLowerCase();
return x+y;
}

this will convert string to an uppercase first letter and lowercase rest of letters.

you use it like so.

var x = "dOg";
x = x.ucfirst(); adam@aauser.com
 

Using javascript, the String object has 2 methods ..

toUpperCase() and toLowerCase()

Greg.
 
Thanks guys. I'm new to JS so this is all very confusing for me and i'm struggling to understand your code. Does this code need to be written for every occasion of a field. They are in the form of [field:'username'][field:'age']for example. How would the code apply to these two fields? Maybe i'll understand better then.
Thanks for all your help.
 
with the functio i provided, all you have to do is copy the function to the top of the page, then for each thing you want in propercase, all you have to do is

var x = document.form.fieldname.value.ucfirst();

adam@aauser.com
 
Thanks again. I placed the function at the top of the page and my field now reads..
<input type=&quot;text&quot; name=&quot;firstname&quot; value=&quot;[field:'firstname']&quot;
var x = document.form.fieldname.value.ucfirst();>

This is obviously incorrect. Can you point me in the right direction?
Thanks a lot.
 
try this:

<input type=&quot;text&quot; name=&quot;firstname&quot; value=&quot;[field:'firstname']&quot;
onblur=&quot;document.form.firstname.value = document.form.firstname.value.ucfirst();&quot;>
adam@aauser.com
 
Thanks, i tried it but it still displays in lowercase.
 
Sorry to take so long to get back to you. First my cable connection went down, now whenever i try to post the page here my computer freezes. Hope this gets through. Would you mind if i emailed you the source for the page?

Thanks for your help again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top