Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about this (<a href="http://jsfiddle.net/VFCw8/3/" rel="nofollow">working demo</a>):</p> <pre><code>&lt;form action="search.html"&gt; &lt;input type="text" value="val1" name="filter1" /&gt; &lt;input type="text" value="val2" name="filter1" /&gt; &lt;input type="text" value="val" name="filter2" /&gt; &lt;input type="submit" value="search" name="cmdSearch" /&gt; &lt;/form&gt; ​ &lt;script&gt; // don't do anything until document is ready $(function() { // register to form submit event $('form').submit(function(e){ // stop the form from doing its default action (submit-GET) e.preventDefault(); // initialise url var url = ''; // keep track of previously enumerated field var prev = ''; // iterate all fields in the form except the submit button(s) $('input:not([type="submit"])', $(this)).each(function(){ // get the name of this field, with null coalesce var name = $(this).attr('name') || ''; // get the value of this field var val = $(this).attr('value'); // does this field have the same name as the previous? if (name.toLowerCase() == prev.toLowerCase()) { // same name therefore we have already appended the name // append value separator url += '|'; } else { // different name, track new name prev = name; // append parameter separator, parameter name, equals char url += '&amp;' + name + '='; } // append value of this field url += val; }); // removing leading ampersand if (url.length &amp;&amp; [0] == '&amp;') { url = url.substring(1); } // insert leading question mark url = '?' + url; // insert url from "action" attribute of the form url = $(this).attr('action') + url; // display url (delete this line) alert(url); // redirect to the new url (simulates the GET) window.location.href = url; }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload