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.
I now got stuck and try to find for hours to find a way.
My Data String looks right now like this:
search = {name:$('#name').val(),group:$('#group').val()};
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:
$('#search_form input[type=text]').each(function(n,element){
if ($(element).val() != '')
{
search_fields = {test :$('#'+element.id).val()};
}
});
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?