Form Get Method: prevent empty fields from submittion in query string

前端 未结 3 1637
无人及你
无人及你 2021-01-06 13:12

I am developing a search form.

Search Form has 2 parts, First simple search with some select, input, and submit button. Second contains many select, check box, radi

相关标签:
3条回答
  • 2021-01-06 14:00

    Try using the following in your $(function(){ ... }) section:

    $('form').submit(function(){$('input[value=]',this).remove();return true;})
    

    this will remove any empty input elements from your form before submitting it. You can of course modify it to include also non-selected selector boxes etc.

    0 讨论(0)
  • 2021-01-06 14:03

    You can bind a function on the form submit event and remove/disable all input with an empty value. Like this :

    your_form.submit(function() {
        your_form.find('input').each(function() {
            var input = $(this);
            if (!input.val()) {
                input.remove(); // or input.prop('disabled', true);
            }
        });
    });
    
    0 讨论(0)
  • 2021-01-06 14:05

    I think you have to validate all those fields before including into the .get() method and do not include to the .get() method those inputs that has no values.

    0 讨论(0)
提交回复
热议问题