Search code examples
jquerycssformssubmission

Prevent Forms From Submitting Based on Width


How can I prevent parts of a form on my page from submitting based on the width of the page?

i.e. if the page is between 900px and 1200px only form input/select items with class .regular-form would be included in the form submission.


Solution

  • You can make sure that the relevant elements are not part of the DOM, and this will make sure they will also not sent in the submission.

    You can use this code to do so:

    if($(window).width() > 900 && $(window).width() < 1200) {
        $('input,select,textarea').not('.regular-form').remove()
    }