dimanche 28 juin 2015

what is wrong in this code for validation of controls?

I use jquery for validation of controls .my codes like this:

function RegisterClient() {
    var bookname = true; var edition = true; var author = true; var price = true; var imgType = true; var imgSize = true;

    if (j('#txt_book_name').val() === null) {   //1
        j('#alertBookName').removeClass('hidden');
        bookname = false;
    }
    if (j('#txt_edition').val() === null) {     //2
        j('#alertEditionbook').removeClass('hidden'); edition = false;
    }
    if (j('#txt_author').val() === null) {       //3
        j('#alertAuthor').removeClass('hidden'); author = false;
    }
    if (j('#txt_price').val() === null) {        //4
        j('#alertPrice').removeClass('hidden'); price = false;
    }
    var fileType = j("#ContentPlaceHolder1_FileUpload1").val().split('.').pop().toLowerCase();
    if (j('#ContentPlaceHolder1_FileUpload1').val() != "" && j.inArray(fileType, ['gif', 'png', 'jpg']) == -1)
    { j('#alertImgType').removeClass('hidden'); imgType = false; }
    if (j('#ContentPlaceHolder1_FileUpload1').val() != null) {
        var sizeImg = j("#ContentPlaceHolder1_FileUpload1")[0].files[0].size/1024;
        if (sizeImg > 25) { j('#alertImgSize').removeClass('hidden'); imgSize = false; }
    }
    if (bookname && edition && author && price && imgType && imgSize) __doPostBack('ctl00$ContentPlaceHolder1$Button1', '');

}

1.In sections 1 ,2,3,4 (j('#txt_...').val() === null) statment is not work curectly

2.(var sizeImg = j("#ContentPlaceHolder1_FileUpload1")[0].files[0].size/1024;)

statment have an error when use firbug .I can show value of j("#ContentPlaceHolder1_FileUpload1")[0].files[0].size with Alert() but here have an error.

Please help.

Aucun commentaire:

Enregistrer un commentaire