Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Texas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy split() and copying from one form field to another

    Greetings!

    I am retro-fitting a Point of Sale system and I have run into a problem with splitting out information entered in one form field and parsing it into 3 others. This works just fine in FireFox but not IE. (I get "object expected"...)

    The purpose here is when the card is swiped in the system, and they hit the tab key on the keyboard, the string that the card enters is split into Card number, Name, Expiration Date.

    (I found a script online and modified it to fit the existing form, I do understand the code, but in the spirit of full disclosure I didn't write it from scratch.)

    This works just fine in Firefox, but IE won't grab the name - only the Number and ExpDate.

    Any suggestions?

    Here is the JavaScript:

    Code:
    function popfield() {
     
        var pmtCreditCard = document.getElementById('pmtCreditCard');
        var PMTCREDITCARDEXPIRATION = document.getElementById('PMTCREDITCARDEXPIRATION');
        var ccCvv = document.getElementById('ccCvv');
        var PmtFirstName = document.getElementById('PmtFirstName');
        var PmtLastName = document.getElementById('PmtLastName');
     	
    	  
     
         var pieces = pmtCreditCard.value.split('^');
                if( pieces.length >= 3 ) {
                    var cardNumber = pieces[0];
                    var name = pieces[1];
                    var exp = pieces[2];
     
                    pmtCreditCard.value = cardNumber.substr(2,(cardNumber.length-1));
                    PMTCREDITCARDEXPIRATION.value = exp.substr(2,2) + exp.substr(0,2);
     
                    namepieces = name.split('/');
                    var l = namepieces[0];
                    var f = namepieces[1];
     
                    PmtFirstName.value = f;
                    PmtLastName.value = l;
     
                    ccCvv.focus();
                }
    		
     }
    The html form is:
    Code:
    <input type="text" name="pmtCreditCard" id="pmtCreditCard" onChange="popfield();" onblur="popfield();" class="POS_inputtext200left_blue"/><br />
    
    Exp. Date: <br />
    <input type="text" name="PMTCREDITCARDEXPIRATION" id="PMTCREDITCARDEXPIRATION" /><br />
    
    Cardholder First Name:<br /> 
    <input type="text" name="PmtFirstName" id="PmtFirstName" /><br />
    
    Cardholder Last Name:<br />
    <input type="text" name="PmtLastName" id="PmtLastName" /><br />
    
    CVV Code:<br />
    <input type="text" name="ccCvv"  size="5" id="ccCvv"/><br />
    TIA!
    -Sunshine

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    So what debugging have you done???

    I would think that, at a minimum, you'd do this:
    Code:
          ...
    alert("raw value::" + pmtCreditCard.value + "::");
         var pieces = pmtCreditCard.value.split('^');
    alert( pieces.length + " pieces found");
    
         if( pieces.length >= 3 ) {
                    var cardNumber = pieces[0];
                    var name = pieces[1];
                    var exp = pieces[2];
    alert("raw cardNumber ::" + cardNumber + "::\nname ::" + name + "\nexp ::" + exp + "::");
                    pmtCreditCard.value = cardNumber.substr(2,(cardNumber.length-1));
                    PMTCREDITCARDEXPIRATION.value = exp.substr(2,2) + exp.substr(0,2);
     
                    namepieces = name.split('/');
    alert("number of namepieces: " + namepices.length);
                    var l = namepieces[0];
                    var f = namepieces[1];
     
                    PmtFirstName.value = f;
                    PmtLastName.value = l;
     
                    ccCvv.focus();
                }
    Run that in both FF and IE and see what the differences are.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Texas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The debugging I had done was limited to JSLint, Firebug and MSFT's debugger.

    I ran this through both browsers, but the results are the same - the raw string comes out correctly, there are 3 pieces found, the name has 2 pieces.. but in IE they are not put into the respective form fields.

    So what did I miss?

    Thanks!
    Last edited by SunshineFreedom; 03-20-2009 at 03:03 PM. Reason: left out question..

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Texas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Update: I stripped the JavaScript and the form out of the other things on that page and tested it by itself - no problems.

    I also noticed that the name variables were being passed in both browsers. Further investigation showed that there were some hidden fields further down the page with the same field names. I'm not sure why the hidden fields were being populated with the data instead of the other ones (document hierarchy?) but anyway...

    I removed the hidden fields and all is well.

    And, I learned a new debugging trick.

    Thanks!
    Susan


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •