title: Autoselect option, and autocomplete textarea values onclick
body: <p>Suppose there is a link (two links, actually), each supposed to be doing something similar and each doing something different.</p>
  
  <pre><code>&lt;a style="cursor:pointer;" name="A"&gt;#&lt;/a&gt;
  &lt;a style="cursor:pointer;" name="A"&gt;Product A&lt;/a&gt;
  &lt;a style="cursor:pointer;" name="B"&gt;#&lt;/a&gt;
  &lt;a style="cursor:pointer;" name="B"&gt;Product B&lt;/a&gt;
  etc.
  </code></pre>
  
  <p>When the # anchor is clicked, it needs to open a popup, prompt for a number, then on submit, autoselect the option and set textarea value to the number entered.</p>
  
  <pre><code>&lt;select&gt;
      &lt;option selected="selected" value="0"&gt;&lt;/option&gt;             
      &lt;option value="A"&gt;Spies&lt;/option&gt;                            
      &lt;option value="B"&gt;Militia&lt;/option&gt;      
  &lt;/select&gt;   
  &lt;/td&gt;
  &lt;td&gt;&lt;input value="0" type="text"&gt;&lt;/td&gt;
  </code></pre>
  
  
  
  <p>But when the Product anchor is clicked, it needs to do the same thing, but just set the selected element to the corresponding value (Product A autoselects the selects to A, etc.)</p>
  
  <p>I have some stuff in JavaScript to make this work, but I'd like it to be in jQuery, and am having a hard time figuring it out.</p>
  
  <p>Some JS:
  The anchors have <code>onclick="var newNumUnits=prompt('How many of Product X do you want to default to? 'Enter amount here'); quickFill(1111115,newNumUnits);"</code>, which takes care of a lot of the stuff, but it gets "large" and "complicated", and I'd really like to see the code be rendered easier (if possible) in jQuery.</p>
  
  <pre><code>function quickFill(ProdID, num) {
      for(i=0; i&lt;document.myForm.elements.length; i++) {
          fieldname = document.myForm.elements[i].name;
          fieldvalue = document.myForm.elements[i].value;
          if (fieldname.indexOf("_") != -1) {
              fieldNameArray = fieldname.split("_");
              smallFieldName = fieldNameArray[0];
              myPUID = fieldNameArray[1];
              if (smallFieldName == "ProdID") {
                  selectfield = document.myForm.elements[i];
                  for (var j=0; j&lt;selectfield.options.length;j++) {
                      if (selectfield.options[j].value == ProdID) {
                          selectfield.options[j].selected=true;
                          textinputfield = document.getElementById("num_"+myPUID);
                          textinputfield.value=num;
                      }
                  }
              }
          }
      }
      updateStatus();
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>EDIT: The actual, unedited code that I'm currently working with:</p>
  
  <pre><code>&lt;tr class="L1"&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="map.php?x=1898&amp;y=2018"&gt;1898, 2018&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;&lt;a href="structDetail.php?x=1898&amp;y=2018"&gt;Combat Outpost&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;select name="struct[213][str]"&gt;
              &lt;option selected="selected" value="0"&gt;&lt;/option&gt;
              &lt;option value="U2" data-price="4000"&gt;Blackshirts&lt;/option&gt;
              &lt;option value="U3" data-price="6000"&gt;Spies&lt;/option&gt;
              &lt;option value="U4" data-price="8000"&gt;Partisans&lt;/option&gt;
              &lt;option value="U7" data-price="15000"&gt;Rebels&lt;/option&gt;
              &lt;option value="U11" data-price="80000"&gt;Oerlikon Cannons&lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;input size="2" maxlength="4" class="txt" name="struct[213][numUnits]" value="0" type="text"&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="L2"&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="map.php?x=1900&amp;y=2018"&gt;1900, 2018&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;&lt;a href="structDetail.php?x=1900&amp;y=2018"&gt;Combat Outpost&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;select name="struct[329][str]"&gt;
              &lt;option selected="selected" value="0"&gt;&lt;/option&gt;
              &lt;option value="U2" data-price="4000"&gt;Blackshirts&lt;/option&gt;
              &lt;option value="U3" data-price="6000"&gt;Spies&lt;/option&gt;
              &lt;option value="U4" data-price="8000"&gt;Partisans&lt;/option&gt;
              &lt;option value="U7" data-price="15000"&gt;Rebels&lt;/option&gt;
              &lt;option value="U11" data-price="80000"&gt;Oerlikon Cannons&lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;input size="2" maxlength="4" class="txt" name="struct[329][numUnits]" value="0" type="text"&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="L2"&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="map.php?x=1901&amp;y=2018"&gt;1901, 2018&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;&lt;a href="structDetail.php?x=1901&amp;y=2018"&gt;Military Installation&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;select name="struct[330][str]"&gt;
              &lt;option selected="selected" value="0"&gt;&lt;/option&gt;
              &lt;option value="U1" data-price="1200"&gt;K-9 Corps&lt;/option&gt;
              &lt;option value="U5" data-price="9000"&gt;Riflemen&lt;/option&gt;
              &lt;option value="U6" data-price="11000"&gt;Sappers&lt;/option&gt;
              &lt;option value="U8" data-price="24000"&gt;J&amp;#228;gers&lt;/option&gt;
              &lt;option value="U9" data-price="27000"&gt;Commandos&lt;/option&gt;
              &lt;option value="U10" data-price="33000"&gt;Red Berets&lt;/option&gt;
              &lt;option value="U12" data-price="110000"&gt;Ford GPW&lt;/option&gt;
              &lt;option value="U13" data-price="222000"&gt;M3 Half-tracks&lt;/option&gt;
              &lt;option value="U14" data-price="350000"&gt;7TP&lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;input size="2" maxlength="4" class="txt" name="struct[330][numUnits]" value="0" type="text"&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="L2"&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="map.php?x=1901&amp;y=2017"&gt;1901, 2017&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;&lt;a href="structDetail.php?x=1901&amp;y=2017"&gt;Light Airfield&lt;/a&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;select name="struct[331][str]"&gt;
              &lt;option selected="selected" value="0"&gt;&lt;/option&gt;
              &lt;option value="U15" data-price="155000"&gt;PZL.23 Kara&amp;#347;&lt;/option&gt;
              &lt;option value="U16" data-price="175000"&gt;R-4 Hoverfly&lt;/option&gt;
              &lt;option value="U17" data-price="650000"&gt;PZL P.11&lt;/option&gt;
              &lt;option value="U18" data-price="1050000"&gt;P-39 Airacobra&lt;/option&gt;
              &lt;option value="U19" data-price="1500000"&gt;C-46 Commando&lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;input size="2" maxlength="4" class="txt" name="struct[331][numUnits]" value="0" type="text"&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>Some stuff that I experimented with before, in JavaScript, that works (goes with the the quickFill function posted above:</p>
  
  <pre><code>&lt;a style="cursor:pointer;" onclick="var newNumUnits=prompt('How many units do you want to default to? \nClick the unit name instead of the number sign to skip this step.','Enter amount here'); quickFill(U3,newNumUnits);"&gt;#&lt;/a&gt;
  &lt;a style="cursor:pointer;" onclick="quickFill(U3);"&gt;Spies&lt;/a&gt;
  &lt;br&gt;
  &lt;a style="cursor:pointer;" onclick="var newNumUnits=prompt('How many units do you want to default to? \nClick the unit name instead of the number sign to skip this step.','Enter amount here'); quickFill(U2,newNumUnits);"&gt;#&lt;/a&gt;
  &lt;a style="cursor:pointer;" onclick="quickFill(U2);"&gt;Blackshirts&lt;/a&gt;
  </code></pre>
  
  <p>That style of anchors then continues for about 30 more combos, different U#'s, different names. What needs to happen is that when the anchor with text is clicked, all selects that contain that same U# are then auto-selected to it, and when the # anchor is clicked, the same thing happens, but also changes the corresponding textarea to the number entered in the  prompt.</p>