Dynamic created JSON String to send via Ajax
<p>I have a form and want to send the data via AJAX in a JSON Format over to my PHP File.
I use jQuery to handle all the events.</p>

<p>I now got stuck and try to find for hours to find a way.</p>

<p>My Data String looks right now like this:</p>

<p>search = {name:$('#name').val(),group:$('#group').val()};</p>

<p>But I have now decided that I only want fields send over, if there is actually a Value set in it. So I created the follwoing part:</p>

<pre><code>$('#search_form input[type=text]').each(function(n,element){
  if ($(element).val() != '') 
  {
    search_fields = {test :$('#'+element.id).val()};
  }
});
</code></pre>

<p>I now want to replace the part where it says test with the input field name and than I would have the value sitting next to it. I hope I explain it right. How would I be able to do this? Because it could be up to 3 Input Fields and I want them to add themself if they have a value or leave them out. Any hint?</p>
