Hello, world!

My English is no good & this is my first javascript code )).
I've a text field for 8-symbol auth code:
-------------------------------------------------------------------
CUT
var sAuthCode   = ""';
var iAuthCount    = -1;
var sAuthCacheCode  = ""';
var iAuthCacheCount   = -1;

$(document).ready(function(){
...
    $("#code").keyup(function(){
        AuthEvent();
    });
...
});

function AuthEvent() {
    var iAuthCode = 0;

    sAuthCode = $("#code").val();
    iAuthCode = $("#code").val().length;

    if (iAuthCode != 8) {
        sAuthCode = "";
        iAuthCount  = -1;
    } else {
        if ((sAuthCode == sAuthCacheCode) && (iAuthCacheCount >= 0)) {
            iAuthCount = iAuthCacheCount;
        } else {
            /* {-1 - server error; 0 - empty balance; >0 - count of
accessible services} */
            $.getJSON(sAuthURL, {code:sAuthCode}, AuthDataReady);
        }
    }

    AuthDraw();
}

function AuthDataReady(json) {
    var iAuthTMP = parseInt(json.Count);
    if (iAuthTMP >= 0) {
        iAuthCount  = iAuthTMP;
        iAuthCacheCount  = iAuthTMP;
        sAuthCacheCode = sAuthCode;
    }
}

function AuthDraw() {
    switch (iAuthCount) {
        case -1:
            SetClass($("#code"), "codeWHITE");
            break;
        case  0:
            SetClass($("#code"), "codeRED");
            break;
        default:
            SetClass($("#code"), "codeGREEN");
            break;
    }
}

function SetClass(el,cls) {
    if (el[0].className != cls) {
        el[0].className  = "";
        el.addClass(cls);
    }
}

-------------------------------------------------------------------
CUT

When code is not in cache & number of symbols in field is 8 - script
makes request to server, but don't change class of field, untill I put
additional any key. HTML part:
<input type="text" name="code" id="code" class="codeWHITE"
maxlength=8 /><p>

What's wrong?

WBR.

Reply via email to