Javascript help needed - var id

Discussion in 'JavaScript' started by mgrohan, Sep 22, 2007.

  1. #1
    Desperately in need of some help. Very lost in my first dabble in javascript.

    I have a script which runs a function on a id number.
    Problem in the script has come with an id number inside, and i am trying to get the id number to be submitted from another page via a form.


    How is it possible to get a form setup to fill [var id=""] and run the function on the submitted id number?

    Last part of the script looks like this: (last two lines is where the variable (id number) is)
    function checkId(pId){
    var arrVerifyCode = [1,0,"x",9,8,7,6,5,4,3,2];
    var Wi = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
    var Checker = [1,9,8,7,6,5,4,3,2,1,1];
    if(pId.length != 15 && pId.length != 18) return "身份证号共有 15 码或18位";
    var Ai=pId.length==18?pId.substring(0,17):pId.slice(0,6)+"19"+pId.slice(6,16);
    if (!/^\d+$/.test(Ai)) return "身份证除最后一位外,必须为数字!";
    var yyyy=Ai.slice(6,10),mm=Ai.slice(10,12)-1,dd=Ai.slice(12,14);
    var d=new Date(yyyy,mm,dd),year=d.getFullYear(),mon=d.getMonth(),day=d.getDate(),now=new Date();
    if (year!=yyyy || mon!=mm || day!=dd || d>now || now.getFullYear()-year>140) return "身份证输入错误!";
    for(var i=0,ret=0;i<17;i++) ret+=Ai.charAt(i)*Wi;
    Ai+=arrVerifyCode[ret %=11];
    return pId.length ==18 && pId.toLowerCase() != Ai?"身份证输入错误!":Ai;
    };

    function getInfo(id){
    //根据身份证取 省份,生日,性别 Go_Rush(阿舜)
    id=checkId(id)
    if (isNaN(id)) return "错误的身份证号码"
    var id=String(id),sex=id.slice(14,17)%2?"男":"女"
    prov=areaCode[id.slice(0,6)] || areaCode[id.slice(0,4)] || areaCode[id.slice(0,2)] || "无法确定"
    var birthday=(new Date(id.slice(6,10),id.slice(10,12)-1,id.slice(12,14))).toLocaleDateString()
    return [prov,birthday,sex]
    }

    var id="440602740328126"
    alert(getInfo(id))
     
    mgrohan, Sep 22, 2007 IP