I have an option.
<form class="i-hate-u">
   <select class="helloMoto" name="helloMoto">
      <option value="">Select...</option>
      <option value="-1">Other</option>
   </select>
</form>
When the end user selects the “other” option, the text input is as follows:
$('.helloMoto').on('change', function() {
      if ($(this).val() == '-1')
            $(this).hide();
            var input_name = $(this).attr('name');
            var input = '<div class="input-group">' +
                             '<input type="text" class="form-control" name="'+input_name+'" placeholder="Type other.">' +
                              '<span class="input-group-btn">' +
                                     '<button class="btn btn-primary" onclick="removeSelectOther(this);"><i class="la la-close"></i></button>' +
                              '</span>' +
                        '</div>';
            $(this).parent().append(input);
});
At the end of this moment, when the save button is clicked by the end user, I serialize the whole form as follows:
var data = $('.i-hate-u').serialize();
As you can see, if the user selects another option, the input will be displayed with the same name. I want to delete if the user selects another option. Is there a way if the serialized value has the same name, skip the first or -1.
source
share