Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use jquery to manipulate the querystring
    primarykey
    data
    text
    <p>I have a select dropdown with id's mapped to values. On the onChange event I want to redirect to the same url but with 'id=value' appended to the querystring.</p> <p>How do I check that this 'id' option isn't already in the querystring (I don't want multiple values) and replace / append as necessary.</p> <p>How do I check if '?' is already in the querystring and append to the url if its not.</p> <p>Is there an easy way with jquery to do this?</p> <p>It must do something similar under the hood for <code>$().ajax(url, {options})</code> calls. I was hoping I could just do <code>$().redirect( url, { id : $(this).val() })</code> or somesuch.</p> <p>Thanks in advance.</p> <p>Note: This page may or may not have a few different query options passed in (which set defaults on other form options) so replacing the whole querystring is not an option.</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;script type="text/javascript" src="/jquery-1.3.2.min.js"&gt;&lt;/script&gt;&lt;/head&gt; &lt;body&gt; &lt;script&gt; $(function(){ $('#selector').change(function(){ // problem if 'id' option already exists var url = location.href + '?;id=' + $(this).val(); location.assign( url ); }); }); &lt;/script&gt; &lt;a href="#" onclick="location.assign( location.pathname )"&gt;reset&lt;/a&gt; &lt;form&gt; &lt;select id='selector' name='id'&gt; &lt;option value='1'&gt;one&lt;/option&gt; &lt;option value='2'&gt;two&lt;/option&gt; &lt;option value='3'&gt;three&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&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.
 

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