0

I would like a piece of that would give number of attachments in a sharepoint list using jQuery. my current code gives a count of one regardless of how many I have. Please help. See my code below:

function PreSaveAction() {
    var count = 0;
    var elm = document.getElementById("idAttachmentsTable");
    if (elm == null || elm.rows.length == 0) {
        console.log(elm);
        document.getElementById("idAttachmentsRow").style.display = 'none';
        var r = confirm("some text");
        if (r == false) {
            return false;
        }
        else {
            return true;
        }

    }
    else {
        count++;

        alert(count);
        return true;
    }
}
  • 1
    Did you try document.querySelector('#idAttachmentsTable').rows.length;? – Salah Jan 10 at 10:04
1

You're incrementing the count variable just once if attachment rows are found:

else {
    count++;

    alert(count);
    return true;
}

Just use elm.rows.length instead to display the actual number of attachments:

else {
    alert(elm.rows.length);
    return true;
}

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.