Prevent Forms From Submitting Based on Width

67 views Asked by At

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.

2

There are 2 answers

12
Dekel On BEST ANSWER

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()
}
1
Serg Chernata On

I don't know if you need to account for the window being dynamically resized or not, so a simple solution would be something like this:

if($(window).width() > 900 && $(window).width() < 1200)
{
    $('.regular-form').prop('disabled', false);
}