JavaScript to format SSN
743607Jun 5 2012 — edited Jun 5 2012Hello,
Im using Apex 4.1, Oracle 11g.
I have a simple page, and the requirement is to automatically format a SSN field to include dashes (-) should the customer only enter in all numbers.
I have written a javascript function to handle this, but no matter how I alter the substrings, the output is not correct.
Using the example below (with an onblur call on the element attribute) for an input of 123456789 returns: 123-3-5
<script type="text/javascript">
function FormatSSN() {
var SNN;
SSN = document.getElementById("P9_SSN").value ;
if (SSN.length == 9) {
document.getElementById("P9_SSN").value = SSN.substring(0,3) + "- " + SSN.substring(3,2) + "-" + SSN.substring(5,4);
}
}
</script>
Ive modified the values in the substring many times but none of the ouput makes any sense.
Can someone please advise.
Thank you,
Laura
Edited by: LauraK on Jun 5, 2012 10:06 AM