title: Selective django/jquery form submission
body: <p>I have a search field at the top of my django template (with no surrounding form tags):</p>
  
  <pre><code>&lt;input name="q" id="id_q" /&gt; 
  &lt;input type="submit" id="id_s" value="Search"&gt;
  </code></pre>
  
  <p>As of now, the search key is submitted with a button press or by clicking enter:</p>
  
  <pre><code>$(function($) {
      $(":submit").click(function() {
          window.location = "{% url search %}?q=" + $("#id_q").val();
      });
  });
  </code></pre>
  
  <p>Now, I'm adding in <a href="http://code.google.com/p/django-registration/" rel="nofollow">django-registration</a>.  As a result, I have a login template that resembles the following:</p>
  
  <pre><code>&lt;form method="post" action="."&gt;{% csrf_token %}
      {% if form.non_field_errors %}
          &lt;div class="form_errors"&gt;
              {% for err in form.non_field_errors %}
                  &lt;div class="form_error_message"&gt;{{ err }}&lt;/div&gt;
              {% endfor %}
          &lt;/div&gt;  
      {% endif %}
      {% for hidden in form.hidden_fields %}
          {{ hidden }}
      {% endfor %}
      {% for field in form.visible_fields %}
          &lt;div class="block"&gt;
              {{ field.label_tag }}
              {{ field }}
              {% for err in field.errors %}
                  &lt;span class="error_message"&gt;{{ err }}&lt;/span&gt;
              {% endfor %}
          &lt;/div&gt;
      {% endfor %}
  
      &lt;div style="padding-left:11em; padding-bottom:1em;"&gt;
          &lt;input type="submit" value="{% trans 'Log in' %}" /&gt;
          &lt;input type="hidden" name="next" value="{{ next }}" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>It took me a while to figure out why attempting to log in sent me to a search page.  I realized that clicking Enter after entering the password was activating the search key, not the username/password submission.</p>
  
  <p>How can I configure the template such that I can type in a search query, hit enter, and activate the search view OR enter my account information, hit enter, and log in?  Basically, how can I specify that an enter key press "belongs" to its requisite function?</p>