Change an input field before submit
<p>I have to encode a domain name (IDNA) for a particular registrar using accents.</p>

<p>I have a simple input field :</p>

<pre><code>&lt;input type="text" id="idndomain" name="sld[0]" size="40" /&gt;
</code></pre>

<p>My jQuery function</p>

<pre><code>$(document).ready(function() { 
 $('#domainform').submit(function(){
  $.getJSON("includes/idna/idna.php", {
   domain: $("input#idndomain").val()
  }, function(data){
   $("div#result").html($('&lt;b&gt;' + data.encoded + '&lt;/b&gt;'));
   $('#idndomain').val(data.encoded);
  });
  return true;
 });
});
</code></pre>

<p>So i'm sending a query to idna.php which encodes the domain name and returns a json array :</p>

<pre><code>{"encoded":"xn--caf-dma.ch"}
</code></pre>

<p>Problem is that the form is being submited with the 'original' value, not the value returned by the json query.</p>

<p>Question is : how to 'wait' for json result first, replace the input field with the encoded string and them submit ?</p>
