Count number of list items in a field

Forums Classic DFFS Count number of list items in a field

Viewing 1 reply thread
  • Author
    Posts
    • #31531
      Jeremy Smith
      Participant

      I would like to setup an alert message that tells me when a field has more or less than x number of items in a sorted or unsorted list

      Example: Field = remainingTasks
      In field there is a list of items present and I want to count how many list items (sorted or unsorted) are existing in that field when I enter the form

      I tried these examples but could figure out how to properly adapt them to work:

      
      
      //Counts the number of List Items in a field
      /*
      var theList = document.querySelector("[id*='remainingTasks_']");
      alert(theList);
      /*
      var theList = document.getElementByRegex("^remainingTasks_.*").getElementsByTagName("ul");
      var numberOfItems = theList.length;
      
      alert(numberOfItems);
      */
    • #31546
      Alexander Bautz
      Keymaster

      Hi,
      Is this a multiline rich text field where you want to count <li> elements?

      If so, try this:

      var html = jQspjs(getFieldValue("YourNoteFieldInternalName"));
      var len = jQuery(html).find("li").length;
      alert(len);

      Replace YourNoteFieldInternalName with the internal name of your multiline field.

      Alexander

Viewing 1 reply thread
  • You must be logged in to reply to this topic.