Popup Disable KB

by ethanpil

HTML

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<a href="#popupDialog" data-rel="popup" data-position-to="window" data-transition="pop" class="ui-btn ui-corner-all ui-shadow ui-btn-inline">Scan ID</a>

<div data-role="popup" id="popupDialog" style="max-width:400px; min-height: 400px;">
    <div data-role="header" data-theme="a">
        <h1>Scan ID</h1>
    </div>
    <div role="main" class="ui-content">
        <label for="idstate">State</label>
        <select id="idstate">
            <option value="MI">Michigan</option>
        </select>
        <h3 class="ui-title">Please scan the ID using your barcode scanner now.</h3>
        <textarea id="idscan">
        @

ANSI 636032030002DL00410211ZM02520027DLDCA
DCB
DCD
DBA02102016
DCSFORDONSKI
DCTSIDNEYMOREY
DBD01152012
DBB02101958
DBC1
DAY
DAU
DAG26120 HARDING ST
DAIOAK PARK
DAJMI
DAK482371007  
DAQF 635 766 609 108
DCF
DCG
DCH
DAH
DCKF635766609108195802102016

ZMZMARev 01-21-2011
ZMB01    
            
        </textarea>
        <a href="#" id="DoneScan" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-transition="flow">Done</a>
    </div>
</div>

<div id="scandata"></div>

JavaScript

$( "#popupDialog" ).on( "popupafteropen", function( event, ui ) {
        $('#idscan').focus();
} );

$('#idscan').on('keydown',function(e)
{ 
    var key = e.charCode || e.keyCode;
    //Disable special keys to prevent wacky scan reaction
    //17 -> ctrl
    //18 -> alt
    //27 -> esc
    //112 to 123 -> f1 to f12

    if( key == 17 || key == 18 || key == 27 ||  (key >= 112 && key <= 123) ) {
        e.preventDefault();
    }

});

$('#DoneScan').click( function() {
    
    //Parse the scan data
    var idtext = $('#idscan').val(); 
    
    data=new Object();
    data.num = idtext.match(/^(DAQ)(.*)$/mg)[0].replace(/^DAJ/,'');
    data.firstname = idtext.match(/^(DCT)(.*)$/mg)[0].replace(/^DCT/,'');
    data.lastname = idtext.match(/^(DCS)(.*)$/mg)[0].replace(/^DCS/,'');
    data.address = idtext.match(/^(DAG)(.*)$/mg)[0].replace(/^DAG/,'');
    data.city = idtext.match(/^(DAI)(.*)$/mg)[0].replace(/^DAI/,'');
    data.state = idtext.match(/^(DAJ)(.*)$/mg)[0].replace(/^DAJ/,'');
    data.zip = idtext.match(/^DAK[\d][\d][\d][\d][\d]/mg)[0].replace(/^DAK/,'');
    data.exp = idtext.match(/^(DBA)(.*)$/mg)[0].replace(/^DBA/,'');
    data.dob = idtext.match(/^(DBB)(.*)$/mg)[0].replace(/^DBB/,'');
    
    html = '<strong>ID Number: </strong>'+data.num+'<br>';
    html += '<strong>First Name: </strong>'+data.firstname+'<br>';
    html += '<strong>Last Name: </strong>'+data.lastname+'<br>';
    html += '<strong>Zip: </strong>'+data.zip+'<br>';
   
    $('#scandata').html(html);
    
    $( "#popupDialog" ).popup( "close" );
});