Search code examples
phpautonumber

Autonumber in inputting new records


My patient number(pnum) need to have a autonumber, like BLHC-2014-0001. I need to automatically have the BLHC-current year-and auto increment of the number with 4 digits when i input new record.


Solution

  • function autonum(){                           
        var c ='BLHC-2014-0001';
    
        var d = c.split("-");
        var e = d[2];
        var f = parseInt(e,10);
        var g = f+1;        
        var str = '' + g;
        var pad = "0000";    
        var resu = str.length < 4 ? (pad+str).slice(-4) : str;
        var lt = d[0]+'-'+d[1]+'-'+resu;               
        document.getElementById("pnum").value =lt;
    }