Note that there are some explanatory texts on larger screens.

plurals
  1. POReset input values from GET url params using jQuery
    primarykey
    data
    text
    <p>This may seem like an odd one, but I want to be able to fill in a static web form using values passed in via a GET param list.</p> <p>Say I have a page, 'self.html': </p> <pre><code>&lt;form action="self.html" method="get" accept-charset="utf-8"&gt; &lt;label for = "40"&gt;New Question?&lt;/label&gt; &lt;input type="radio" name="40" id="40" value="Yes"&gt; Yes &amp;nbsp; &lt;input type="radio" name="40" id="40" value="No"&gt; No &lt;label for = "41"&gt;What's your favourite colour?&lt;/label&gt; &lt;input type="text" name="43" value="" id="41"&gt; &lt;/form&gt; </code></pre> <p>I need the form to submit itself whenever an input changes:</p> <pre><code> $(document).ready(function(){ $('input').change(function(){ $("form:first").submit(); }); // collate_results(); }); </code></pre> <p>but obviously I want to keep the values, so that they're not reset on the reload.</p> <p>(Why? Because I'm doing it in a FileMaker web view, and the only way to pull data out of a form is to get the source - url - and parse it... hence I need to url to update to reflect the current state of the form, and also be able to pass in the data for any new records I want to display...)</p> <p>UPDATE:</p> <p>Here's my non-working code - it's fine single value fields, but fails for radio buttons...</p> <pre><code>$('input').change(function(){ $("form:first").submit(); }); var qString = jQuery.url.attr("query"); if(qString) { qString = qString.split("&amp;"); $(qString).each( function() { var parts = this.split("="); var item = $('#'+parts[0]); if($(item).attr('type') == 'text') { $('#'+parts[0]).val(parts[1]); }; if($(item).attr('type') == 'radio') { $(item).each(function() { console.log(this); if($(this).val() == parts[1]) { $(this).attr('checked','checked'); } else { $(this).attr('checked',''); } }); }; }) } }); </code></pre> <p>The problem is that I <em>will</em> have multiple radio buttons with values of yes, no, na on the form, so the way that jQuery wants to do it doesn't seem to apply. I can re-id the radio button if that helps...</p> <pre><code>&lt;form action="self.html" method="get" accept-charset="utf-8"&gt; &lt;label for = "40"&gt;New Question?&lt;/label&gt; &lt;input type="radio" name="47" id="47_yes" value="Yes"&gt;Yes &amp;nbsp; &lt;input type="radio" name="47" id="47_no" value="No" checked&gt; No &lt;label for = "48"&gt;What's your favourite colour?&lt;/label&gt; &lt;input type="text" name="48" value="" id="48"&gt; &lt;/form&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. 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