title: Disabling a submit button using JQuery if a value has not been selected from a specific dropdown
body: <p>I am trying to disable a submit button if a value from a specific dropdown has not been selected.  The code for the dropdown and button looks like this:</p>
  
  <pre><code>    &lt;li&gt;
      &lt;select name="names" id="names"&gt;
      &lt;option value=""&gt;Constituency&lt;/option&gt;
      &lt;!-- populates the drop down with names --&gt;
      &lt;?php foreach ($cons as $constituency): ?&gt;
      &lt;option value="&lt;?php htmlout($constituency['ids']); ?&gt;"&gt;
      &lt;?php htmlout($constituency['names']); ?&gt;
      &lt;/option&gt;
      &lt;?php endforeach; ?&gt;
      &lt;?php if (isset($selectError)): ?&gt;
      &lt;p&gt;&lt;?php htmlout($selectError); ?&gt;&lt;/p&gt;
      &lt;?php endif; ?&gt;
      &lt;/select&gt;
      &lt;/li&gt;
  
      &lt;li&gt;&lt;input type="hidden" name="action" value="search"&gt;&lt;/li&gt;
      &lt;li&gt;&lt;input type="submit" value="SEARCH" class="button search" id="jsbutton" disabled="disabled"&gt;&lt;/li&gt;
  </code></pre>
  
  <p>So the dropdown has an id of 'names' and the button has an id of 'jsbutton' and is set to 'disabled' .</p>
  
  <p>I then try to target it with the following JQuery but the button remains disabled regardless:</p>
  
  <pre><code>    $(document).ready(function() {
  
      if ($('#names').val() = '')
      {
          $('#jsbutton').attr('disabled', 'disabled');  
      }
      else
      {
          $('#jsbutton').removeAttr('disabled');
      }
      });
  </code></pre>
  
  <p>So what I am trying to do is:</p>
  
  <ul>
  <li>Check if value has been selected from dropdpwn.</li>
  <li>IF it hasn't then leave button disabled.</li>
  <li>ELSE a value has been selected from the dropdown and therefore the button should be enabled.</li>
  </ul>
  
  <p>Any help on this is appreciated.</p>
  
  <p>PHP TO POPULATE THE DROPDOWN:</p>
  
  <pre><code>          try
        {
          $cons_result = $pdo-&gt;query("SELECT id, name 
                                 FROM constituency 
                                 ORDER BY name");
        }
        catch (PDOException $e)
        {
          $error = 'Error fetching constituencies from database!' . $e-&gt;getMessage();
          include 'error.html.php';
          exit();
        }
  
  
        foreach ($cons_result as $rows)
        {
          $cons[] = array('ids' =&gt; $rows['id'], 'names' =&gt; $rows['name']);
        }
  
        include 'searchform.html.php';
      }
  </code></pre>