title: Passing URL variable via HTML form submission using either PHP or JavaScript
body: <p>I need to simply pass a form variable into a URL variable. I suspect that it's something easy to do but I'm having a hard time finding clear steps (that aren't tons of code) online anywhere.</p>
  
  <p>Here's my current form code</p>
  
  <pre><code>&lt;form id="zip_search" method="post" action="dealers.php"&gt;
      &lt;label for="zipfield"&gt;&lt;a href="dealers.php"&gt;Find a Dealer&lt;/a&gt;&lt;/label&gt;
      &lt;input name="tZip" type="text" id="zipfield" value="ZIP CODE" onblur="if(this.value=='') this.value='ZIP CODE';" onfocus="if(this.value=='ZIP CODE') this.value='';" /&gt;
      &lt;input type="image" value="Submit" class="submitbutton" src="/images/submit_button.gif" /&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>And all I need is for it to send the browser to something like this:</p>
  
  <pre><code>http://www.mydomain.com/dealers.php?zip=55118
  </code></pre>
  
  <p>Thank you in advance for any help.</p>
  
  <hr>
  
  <h2>Update to question</h2>
  
  <p>Thanks to Drew and Anton's responses here's an update. Changing the input name attribute to match the URL var name (tZip to zip) along with changing POST to GET did the trick but for some reason it's adding two additional URL variables as well (&amp;x=0&amp;y=0). I'm guessing this is something incorrect with my PHP code as I'm not a PHP wizard by any stretch. Here's all the code:</p>
  
  <p><strong>PHP Function</strong></p>
  
  <pre><code>&lt;?php
  function processForm() {
      $zipCode = $_GET['zip'];
      $url = "dealers.php?zip=" . $zipCode;
      header("Location: $url");
      exit;
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;form id="zip_search" method="get" action="dealers.php"&gt;
      &lt;label for="zipfield"&gt;&lt;a href="dealers.php"&gt;Find a Dealer&lt;/a&gt;&lt;/label&gt;
      &lt;input name="zip" type="text" id="zipfield" value="ZIP CODE" onblur="if(this.value=='') this.value='ZIP CODE';" onfocus="if(this.value=='ZIP CODE') this.value='';" /&gt;
      &lt;input type="image" value="Submit" class="submitbutton" src="/images/submit_button.gif" /&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p><strong>URL Output Example</strong></p>
  
  <pre><code>http://www.domain.com/dealers.php?zip=12345&amp;x=0&amp;y=0
  </code></pre>
  
  <hr>
  
  <h2>Additional Related Question</h2>
  
  <p>How is this working if processForm() is only defined but not called anywhere else. It seems to me that the processForm() function should be in the action attribute in the opening form element. Any insight? Thanks in advance.</p>