v3.5.*
This mod makes the customer data neater, by capitalising the
first letters of the data entered and saves you editing it later.
joe bloggs becomes
Joe
Bloggs
1) Make a file called capitalise.js and shove it in the skin1 directory.
Add this code to it...
Code:
////////////////////////////////////////////////////////////////////////
//Capitalise the first letter in a textbox once the value is changed
//Call as follows onChange="Proper(this); return true;"
function Proper(o) {
var s = o.value;
var out = "";
if (s.length > 0) {
var c = true;
// process each character one at a time
for (var i=0; i < s.length; i++) {
var t = s.substring(i,i+1).toUpperCase();
// if not alpha cap next character
cmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ'";
if ( cmp.indexOf(t) < 0) {
c = true;
}
else {
if (c) {
c = false;
}
else {
t = t.toLowerCase();
}
}
// take special cases like Mc and Mac and Roman numerals
if ( i > 1 ) {
temp = s.substring(i-2,i).toUpperCase();
if ( temp == "MC" ) {
t = t.toUpperCase();
}
cmp = " II V X";
roman = "IVX";
roman2 = "IVX ";
if ( cmp.indexOf(temp) >= 0 && roman.indexOf(t.toUpperCase()) >= 0 &&
roman2.indexOf(s.substring(i+1,i+2).toUpperCase() ) >= 0 ) {
t = t.toUpperCase();
}
}
if ( i > 2 ) {
temp = s.substring(i-3,i).toUpperCase();
if ( temp == "MAC") {
t = t.toUpperCase();
}
if ( ( temp == " XI" || temp == " VI" || temp == " XX" || temp == "XV" ) && ( t.toUpperCase() == "I" || t.toUpperCase() == "V" ||
t.toUpperCase() == "X" ) ) {
t = t.toUpperCase();
}
} out += t;
}
o.value = out;
} return true;
}
2) Then find xcart/skin1/customer/home.tpl
Add this code between <head> and </head>
Code:
<script language=JavaScript1.3 src="{$SkinDir}/capitalise.js"></script>
3) Then locate the following templates in the
xcart/skin1/main directory
register_billing_address.tpl
register_shipping_address.tpl
register_personal_info.tpl
states.tpl (only if you have the states field as an input field)
see also
xcart/skin1/help/contactus.tpl
if you want to use it on the 'contact us' form
Call the script by adding this code to the input fields:
Code:
onChange="Proper(this); return true;"
eg.
Change
Code:
<input type=text name=b_firstname size=32 maxlength=32 value="{$userinfo.b_firstname}">
to
Code:
<input type=text name=b_firstname size=32 maxlength=32 value="{$userinfo.b_firstname}" onChange="Proper(this); return true;">
etc.
Hope someone finds this useful.
See also a method for capitalising the zip/postal code
http://forum.x-cart.com/viewtopic.php?t=8112