Skip to content

Instantly share code, notes, and snippets.

@zakhardage
Created November 20, 2013 04:50
Show Gist options
  • Select an option

  • Save zakhardage/7557890 to your computer and use it in GitHub Desktop.

Select an option

Save zakhardage/7557890 to your computer and use it in GitHub Desktop.
I needed to convert the customers 3-character input into lowercase-uppercase-lowercase (e.g. "eMc").
<div class="custom monogram">
<label>ADD A MONOGRAM:</label>
<input type="text" onkeyup="caseChange()" id="monogram" maxlength="3" />
<p class="notes">Please enter your monogram here in the correct order: first, last, middle. Monogram may not be changed to another style or full name.</p>
</div> <!-- end .custom .monogram -->
<script>
function caseChange() {
var str = document.getElementById('monogram').value;
var one = str.substring(0,1);
var m1 = one.toLowerCase();
if(str.length>1) {
var two = str.substring(1,2);
var m2 = two.toUpperCase();
}
if(str.length==3) {
var thr = str.substring(2,3);
var m3 = thr.toLowerCase();
document.getElementById('monogram').value = m1+m2+m3;
}
if(str.length==1) {document.getElementById('monogram').value = m1;}
if(str.length==2) {document.getElementById('monogram').value = m1+m2;}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment