Front end developer Front end developer - 10 days ago 4
jQuery Question

I don't want to send an Empty value

I am sending data to the server with TextBox. But I specifically want to send textboxes with value. If no value is entered, the textbox will not be sent.
How would I be able to send textboxes with a value?

$.ajax({type: "GET",
url:myurl,
success: function (msg, result, status, xhr) {
var obje = jQuery.parseJSON(msg)
var i = 0;
$('#wrapper *').filter(':input').each(function () {
$(this).attr('id', i);
if (i)
field += " and ";
field = field + "[" + obje[i].Name+ "]" + "=" + "'" + $(this).val() + "'";
i++;

});

Answer

try this

 var txtvalue=$(this).val();
  if(txtvalue !=""){
    if (i)
     {

            field += " and ";
        field = field  + "[" + obje[i].Name+ "]" + "=" + "'" + $(this).val() + "'";
    }

 i++;
}
Comments