Reformat using javascript

Discussion in 'Software' started by tridom, Mar 15, 2004.

  1. tridom

    tridom Private E-2

    I've got a problem using javascript in the onBlur for a social security number input. The javascript function I am using is as follows:

    function checkSSN() {
    var SSN = document.getElementById('SSN');
    var nums = SSN.value.replace(/[^0-9]/ig, '');
    if (!nums) {
    return;
    }
    if (nums.length == 9) {
    SSN.value = nums.substring(0, 3) + '-' +
    nums.substring(3, 5) + '-' +
    nums.substring(5, 9);
    } else {
    SSN.value = nums; }
    }

    It works fine and changes the SSN to the proper format (XXX-XX-XXXX) when the input box loses focus (just as it should), BUT when I attempt to enter the value to a table in SQL 2000, it tries to enter the data as the SSN with a box in front of it- and so I get a "data will be truncated" error. The box only shows up when I increase the size of the column in the database so it will accept the input. It doesn't show up anywhere in the variables in the ASP page.

    Any idea on how to fix this??? I've been trying to figure it out for a couple hours and I give up. Maybe I'll just go back to using 3 input boxes instead of trying to make it easier for the user :)->).

    Probably something dumb that I'm missing.

    Any help will be greatly appreciated! Thanks in advance.
     
  2. Kodo

    Kodo SNATCHSQUATCH

    what's the datatype of your field?
     
  3. tridom

    tridom Private E-2

    Thanks...but

    Kodo- I appreciate the response, but I solved the problem. It was one of those cases where I had to sleep on it and come (had been looking at code for over 8 hours at the time.

    Turned out it wasn't in the javascript. When I built the sql statement I did it on 3 lines, so I had &chr(13) at the end of each line. When I started the line with the variable that contained the SSAN, I started it sql=sql&strSSN. That caused it to pick up the chr(13) from the previous line and make it part of the value to insert. Its fixed now.

    But thanks for being willing to try and help. It was a DUH Dumb mistake and the javascript is pretty straight forward and I was tired so it drove me nuts.
     
  4. Kodo

    Kodo SNATCHSQUATCH

    well, glad you got it sorted.. sorry it took so long to get to this post. Didn't see it.
     
  5. tridom

    tridom Private E-2

    What's with...

    Hey Kodo- what's with the cannoli icon? et tu Italiano?
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds