Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not possible to update the part after the question mark without refreshing the page, but you can update the URL hash (so it looks like <a href="http://domain.com/file.php#fav_fruit=apple" rel="nofollow">http://domain.com/file.php#fav_fruit=apple</a>). I don't know how to do it in plain old JavaScript but I have done this using <a href="http://www.jquery.com" rel="nofollow">jQuery</a> and the <a href="http://www.asual.com/jquery/address/" rel="nofollow">jQuery.address plugin</a>.</p> <p>You can then set the textbox to update the URL every time the value is changed by doing something like the following:</p> <pre><code>$("#mytextbox").change(function(){ $.address.parameter("fav_fruit", $(this).value()); }); </code></pre> <p>The good thing with this plugin is that you can attach a function so that you can detect when the URL is changed (i.e. when the bookmark is reloaded):</p> <pre><code>$.address.externalChange(function(){ var favFruit = $.address.parameter("fav_fruit"); // Set any textboxes, values, etc }); </code></pre> <p>By default, the plugin will create a history action everytime a value is update (so you can press back/forward). You wouldn't want this so you'd have to have this before you set any values:</p> <pre><code>$.address.history(false); </code></pre> <hr> <p><strong>Update</strong>: Here's what it looks like in plain old JavaScript:</p> <pre><code>// Stores name/value pairs that have changed var updatedValues = []; // Updates or adds an element to 'updatedValues' function change(obj) { updatedValues[obj.name] = obj.value; setHash(); } // Gets all the changes variables/values and sets the hash function setHash() { var arr = []; for (x in updatedValues) { arr.push(x + '=' + escape(updatedValues[x])); } location.hash = arr.join('&amp;'); } // Returns an object to return the values from the hash string function readHash() { var locationHashParts = location.hash.substr(1).split('&amp;'); var params = {}; for (paramName in locationHashParts) { var keypair = locationHashParts[paramName].split('='); params[keypair[0]] = unescape(keypair[1]); } return params; } </code></pre> <p>It's not pretty, but it works. <code>change</code> is what you set your form elements to call and it will set the URL hash with the required bits. When you want to set the values in the form fields (for example, when you load the page), you call the <code>readHash</code> to get an object with all the parameters/values in the <code>location.hash</code> field.</p> <p>Example of it working at <a href="http://jsfiddle.net/ENHFN/" rel="nofollow">http://jsfiddle.net/ENHFN/</a> (although you can't see the location hash change, it uses the variable). I kept getting errors when I tried to separate it out.</p>
    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.
    3. 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