aDisable Select List Items based on existence of ID in page
<p>So I happen to have a form where the user selects an item from the select list, and adds it to the page by submitting the form. Both form and the resulting list of items are on the same page, so the list of items can include the primary key of the item that had been added as an ID in the tag surrounding the item that had been added.</p>

<p>I want to be able to disable the entry in the select list of any item previously added to the page. My JavaScript  is such:</p>

<pre><code>$('#EquipmentId').each(function () {
  if ($('#' + $(this).val()).length) {
    $(this).attr('disabled', 'disabled');
  }
});
</code></pre>

<p>The select list (#EquipmentId) is a list of machines, where the Value is the primary key of the machine as a Guid. When the list of selected machines are written to the page, they are in a list where the list items have the Guid of the machine as their ID (<code>&lt;li id="[Guid]"&gt;Equipment&lt;/li&gt;</code>).</p>

<p>Unfortunately, right now the entries in the select list are not being properly disabled, even though there are several machines that have been selected. Even though the IDs are on the page, the JavaScript doesn't seem to be disabling the corresponding entries in the select list so the machine cannot be added to the page twice.</p>

<p>Suggestions?</p>

<hr>

<p><strong>EDIT:</strong> I think people are getting confused as to what I am looking for and what I need to modify. </p>

<p>The select list is the <code>#EquipmentId</code>. It exists only once. It provides a list of machines, with the primary key Guid as the Value and the name of the machine as the text. The user can add a machine by selecting it and submitting the form. Once a machine is added to the page, it shows up in the HTML as <code>&lt;li id="[Guid]"&gt;Equipment&lt;/li&gt;</code>, with the Guid being its Value in the select list. I need the JavaScript to see if, for each item in the Select List, there exists an ID on the page with its Value. If there does exist such an ID, disable that specific entry in the Select List.</p>

<p>This will prevent the same machine from being added to the page more than once, and ensures that any one Guid exists as an ID only once on the page (if it exists at all).</p>

<hr>

<p><strong>Edit 2:</strong> Here is my raw HTML:</p>

<pre><code>&lt;form class="form-inline body-form" role="form" method="post" action="/HEO/AssignEquipment/70b079f0-3a45-e611-8274-14feb5fbeae8"&gt;
  &lt;div class="form-group col-sm-4"&gt;
    &lt;label class="control-label" for="EquipmentId"&gt;Equipment&lt;/label&gt;
    &lt;select id="EquipmentId" class="form-control" name="EquipmentId"&gt;
      &lt;option value=""&gt;« ‹ Select › »&lt;/option&gt;
      &lt;option value="de3e5768-612e-43e8-a6a4-cce6060e66c7"&gt;Articulated Rock Truck&lt;/option&gt;
      &lt;option value="80aa47af-bd75-4a98-8aca-9a8fd2c70a0a"&gt;Compactor&lt;/option&gt;
      &lt;option value="5087a0db-00a8-4a18-ad0a-59388e540f83"&gt;Crane&lt;/option&gt;
      &lt;option value="04e4a3d3-8199-4250-a53e-0be119f2b48a"&gt;Delimber&lt;/option&gt;
      &lt;option value="6de52fd3-2b7e-4680-8db5-af8c1bf74b55"&gt;Dozer &lt;/option&gt;
      &lt;option value="a68d8f70-6bae-4b12-8e8e-cbd42ac0ed60"&gt;Excavator&lt;/option&gt;
      &lt;option value="ec06f40a-7177-4604-b3e2-021fdb3b72cc"&gt;Feller Byncher&lt;/option&gt;
      &lt;option value="4936faa7-25fd-4775-a733-a84decccf988"&gt;Forklift&lt;/option&gt;
      &lt;option value="33f9826c-1cbe-43a5-b37d-cf7dca9490c9"&gt;Front End Loader&lt;/option&gt;
      &lt;option value="d56b6fed-198d-48c8-8f90-5d447a242970"&gt;Grader&lt;/option&gt;
      &lt;option value="e5c4b730-2815-4dcf-888d-2f12e4d6c1af"&gt;Horizontal Grinder&lt;/option&gt;
      &lt;option value="f057c8fc-515e-4098-bb05-8ece3ff0332d"&gt;Loader&lt;/option&gt;
      &lt;option value="70cfe933-8ab6-4871-b784-47ddb0a379e3"&gt;Milling Equipment&lt;/option&gt;
      &lt;option value="35ca60e0-cdd6-4b45-bf55-63755b979172"&gt;Motor Grader&lt;/option&gt;
      &lt;option value="683fa8d3-c19d-4fe5-865f-809e057c2c90"&gt;Mulcher&lt;/option&gt;
      &lt;option value="387555cf-b823-4ac2-84dc-4e1f89baa61b"&gt;Pipelayer&lt;/option&gt;
      &lt;option value="92b03391-930a-456c-8f06-a3b3ab9a3d73"&gt;Processor&lt;/option&gt;
      &lt;option value="252c3db4-2fee-4c23-944b-2f362e1961c8"&gt;Rock Breaker&lt;/option&gt;
      &lt;option value="dfbd74a7-7b3f-48a2-a31b-81d520be22ca"&gt;RubberTire Backhoe&lt;/option&gt;
      &lt;option value="e9a55159-0685-4e1d-b363-b3432d9cfb28"&gt;Skidder&lt;/option&gt;
      &lt;option value="f0a326a9-9533-4655-8822-a9d1b2ed959e"&gt;Skidsteers&lt;/option&gt;
      &lt;option value="da107259-84a6-4662-abbb-00c8ece89499"&gt;Skip Loader&lt;/option&gt;
      &lt;option value="43f2ba52-40c4-442f-a5f4-d685346e992b"&gt;Telehandler&lt;/option&gt;
      &lt;option value="564289b9-b39c-47e1-941a-4bbafba1bd0f"&gt;Tub Grinder&lt;/option&gt;
      &lt;option value="9aa99772-1204-4c43-8e08-505971dbc932"&gt;Underground Truck&lt;/option&gt;
    &lt;/select&gt;
  &lt;/div&gt;
  &lt;div class="form-group col-sm-4"&gt;
    &lt;label class="control-label" for="EquipmentHours"&gt;Hours&lt;/label&gt;
    &lt;input id="EquipmentHours" class="form-control required text-box single-line" type="text" value="" name="EquipmentHours" maxlength="5"&gt;
  &lt;/div&gt;
  &lt;div class="form-group col-sm-4"&gt;
    &lt;br&gt;&lt;button class="btn btn-dark btn-lg" type="submit"&gt;Submit&lt;/button&gt;
  &lt;/div&gt;
  &lt;div class="clearfix"&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;hr&gt;
&lt;h3&gt;Equipment Hours for this job:&lt;/h3&gt;
&lt;dl class="widelist"&gt;
  &lt;dt id="de3e5768-612e-43e8-a6a4-cce6060e66c7"&gt;Articulated Rock Truck&lt;/dt&gt;&lt;dd class="hovershow"&gt;100&lt;a class="glyphicon glyphicon-remove" title="Delete Machine Entry" href="/HEO/DeleteEquipment/de3e5768-612e-43e8-a6a4-cce6060e66c7"&gt; &lt;/a&gt;&lt;/dd&gt;
  &lt;dt id="6de52fd3-2b7e-4680-8db5-af8c1bf74b55"&gt;Dozer &lt;/dt&gt;&lt;dd class="hovershow"&gt;500&lt;a class="glyphicon glyphicon-remove" title="Delete Machine Entry" href="/HEO/DeleteEquipment/6de52fd3-2b7e-4680-8db5-af8c1bf74b55"&gt; &lt;/a&gt;&lt;/dd&gt;
&lt;/dl&gt;
</code></pre>

<p>As you can see above, since both "Articulated Rock Truck" and "Dozer" are present on the page, below the <code>form</code> entirely, I want their entries in the Select List to be set to "disabled" automatically on page load by the JavaScript. I don’t want those two Select List entries to vanish -- I only want them disabled, so they cannot be selected again for another form submission.</p>