...

View Full Version : Proper Case



crmpicco
07-06-2005, 09:57 AM
forename.toUpperCase()
Is there a way to change this value to Proper Case, i.e. forename = picco
change to Picco

martin_narg
07-06-2005, 10:29 AM
<script>
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.substring(1,this.length).toLowerCase();
}
</script>


Usage:



var str = "martin_narg";
var string1 = str.capitalize();
// output is Martin_narg

// or

var string2 = ("martin_narg").capitalize();
// output = Martin_narg


This is an extension to the string object, so you can use it with any JavaScript string without repeating the code.

Hope this helps

m_n

crmpicco
07-06-2005, 01:11 PM
i need to change the start of this for loop depending on a condition
how do i do that? this code doesnt work.


if(document.form.nochd==1)
{
for (i=0; i<document.form.nochd.value; i++)
{
}
else
{
for (i=0; i<document.form.nochd.value-1; i++)
{
}

crmpicco
07-06-2005, 01:16 PM
fix:



if(document.form.nochd.value==1)
{
nochdvalue=document.form.nochd.value
}
else
{
nochdvalue=document.form.nochd.value-1
}

for (i=0; i<nochdvalue; i++)
{



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum