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;
}
  • thank you. worked like a charm – Vusi85 2 days ago

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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