Click to See Complete Forum and Search --> : Auto FOrmat SSN


jonah002
10-28-2003, 06:40 PM
Hello all,

I've been trying to get a script to auto format a social security number as a person types it in and came up with dFilter but it eats **** when you go type with the numpad. THat actually creates more problems. Anyone know of a good script that can do this. THere are so many good ones for dates but none for ssn.

THanks,
JC

jc@chapter4.cc

simpson97
10-29-2003, 01:35 AM
Try something like this:

<html>
<head>
<script>
_dom = document.all ? 3 : (document.getElementById ? 1 : (document.layers ? 2 : 0));
function keyPress(e) {
if(document.form0.ssn.value.length > 8) {
alert('Too many numbers');
return false;
}
if(document.all) e=window.event;
if(_dom == 2) {
if(e.keyCode == 8 || e.keyCode > 47 && e.keyCode < 59 || e.keyCode > 95 && e.keyCode < 106) return true;
return false;
}
if(_dom == 3) {
if(e.keyCode == 8 || e.keyCode > 47 && e.keyCode < 59 || e.keyCode > 95 && e.keyCode < 106) return true;
return false;
}
}
window.onload = init;
function init() {
document.onkeydown = keyPress;
}
</script>
</head>
<body>
<form name=form0>
<input type=text name=ssn>
<input type=button value='Clear ssn' onclick="javascript:document.form0.ssn.value = ''">
</form>
</body>
</html>

Bob

jonah002
10-29-2003, 08:33 AM
Thanks but that does not work. I am looking for something to automatically add the dashes while typing in the social security number. I know how to validate it "THAT IS NOT WHAT I WANT" ... I want to automatically add "THE DASHES"

requestcode
10-29-2003, 09:18 AM
This was thrown together rather quickly so someone else could probably make it more effecient, but it does work and will not allow anything else but numbers and of course dashes.
<html>
<head>
<title>Test</title>
<script language="JavaScript">
function fmtssn()
{
re = /\D/g; // remove any characters that are not numbers
socnum=document.myform.socsec.value.replace(re,"")
sslen=socnum.length
if(sslen>3&&sslen<6)
{
ssa=socnum.slice(0,3)
ssb=socnum.slice(3,5)
document.myform.socsec.value=ssa+"-"+ssb
}
else
{
if(sslen>5)
{
ssa=socnum.slice(0,3)
ssb=socnum.slice(3,5)
ssc=socnum.slice(5,9)
document.myform.socsec.value=ssa+"-"+ssb+"-"+ssc
}
else
{document.myform.socsec.value=socnum}
}
}
</script>
</head>
<body onload="document.myform.socsec.focus()">
<form name="myform">
<center>
Social Security Number:&nbsp<input type="text" size="9" name="socsec" maxlength="11" onKeyPress="fmtssn()">
</center>
</form>
</body>
</html>

jonah002
10-29-2003, 11:55 AM
Thank you so much ... would you happen to know how to autofill text boxes in a form based on a selection made on a select field. URL to view is as follows http://dev.chapter4.cc/uk/test/doctors.cfm

THanks,
JC

requestcode
10-29-2003, 12:51 PM
You could try this example, but you will have to either place your form elements in the same order as your variables in the array or place the variables in the array in the same order as your form elements. This example sets up an array of the information you want separating each value with a comma. The function gets called when an option is selected. Within the function the the values in the first array are split up when a comma is encountered and placed into another variable that becomes an array by default. then a for loop bumps through the form elements populating them with the values.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="javascript" type="text/javascript">
var docarr=new Array()
docarr[0]=""
docarr[1]="Emily,Reding,678 lors turn,floor 2,flat 3,London,Craver,99999,5869999,125252,test2@test.com,1234,12542"
docarr[2]="James,Thomas,780 Juustin Blvd, , ,heathrow,Hunter,58652,55555555,66666666,test@test.com,58656,522585"
function populate(objval)
{
docarr2=docarr[objval].split(",") // split the string when you encounter a comma
// to create an array
if(objval!=0)
{
arrlen=docarr2.length
for(i=0;i<arrlen;i++)
{
a=i+1 // add one to bypass the select element
document.testFrm.elements[a].value=docarr2[i]
}
}
}

</script>
<body onload="document.testFrm.docNurse_firstName.focus();">
<form name="testFrm" method="post">
<select name="docNurse_id" onchange="populate(this.options[this.selectedIndex].value)">
<option value="0">New Doctor/Nurse</option>

<option value="1">Emily Reding</option>

<option value="2">James Thomas</option>

</select>
<br><br>
<table width="646" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../../../images/spacer.gif" width="133" height="1" border="0"></td>
<td><img src="../../../images/spacer.gif" width="190" height="1" border="0"></td>
<td><img src="../../../images/spacer.gif" width="113" height="1" border="0"></td>
<td><img src="../../../images/spacer.gif" width="210" height="1" border="0"></td>
<tr>
<td align="right" class="font">First Name :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_firstName" tabindex="16"></td>
<td align="right" class="font">Last Name :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_lastName" tabindex="17"></td>
</tr>
<td align="right" class="font">Address :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_address1" tabindex="22"></td>
<td align="right" class="font">&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_address2" tabindex="23"></td>
</tr>
<tr>
<td align="right" class="font">Code :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_code" tabindex="18"></td>
<td align="right" class="font">&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_address3" tabindex="24"></td>
</tr>
<tr>
<td align="right" class="font">E-mail :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_email" tabindex="19"></td>
<td align="right" class="font">Town :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_town" tabindex="25"></td>
</tr>
<tr>
<td align="right" class="font">Phone :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_phone" tabindex="20"></td>
<td align="right" class="font">County :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_county" tabindex="26"></td>
</tr>
<tr>
<td align="right" class="font">Fax :&nbsp;</td>
<td><input type="text" class="textbox" name="docNurse_fax" tabindex="21"></td>
<td align="right" class="font">Postal Code :&nbsp;</td>
<td><input type="text" name="docNurse_postalCode" size="10" maxlength="10" tabindex="27"></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td align="right" class="font">Tax ID :&nbsp;</td>
<td><input type="text" class="textbox" name="drTaxID" tabindex="28"></td>
</tr>
</table>
</form>
</body>
</html>

jonah002
10-29-2003, 01:09 PM
Than you so much ....