In Bootstrap, how can I prevent form fields from being responsive when the screen resolution is in the col-xs or col-sm range?

I'm struggling to grasp this concept. In my form, there are roughly 20 input values that display when utilizing col-md or col-lg, but for smaller screens (col-xs and col-sm), I want to use a dropdown instead.

The issue arises when I attempt to hide the fields with hidden-sm or hidden-xs; they remain in the form and still get processed upon submission, resulting in the value being passed twice - once as a radio button and once as a dropdown selection.

I suspect many others are facing similar challenges. What is the appropriate method to completely disable input fields in Bootstrap (not just hide them) for smaller screen sizes? The inputs currently look like this:

<input type="radio" name="category_id" value="1" id="cat1">
<input type="radio" name="category_id" value="2" id="cat2">
<input type="radio" name="category_id" value="3" id="cat3">
...

Answer №1

It seems like I've just found the solution to my question all by myself! Hooray! Feel free to point out any errors in my approach or suggest improvements, but here's what is currently working for me:

 $(window).resize(function() {
      if ($(window).width() < 992) {
         $( "input[name$='category_id'" ).prop( "disabled", true ); //Disable
      }
         else {
         $( "input[name$='category_id'" ).prop( "disabled", false ); //Enable
      }
  });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Populate DataTable header labels with data from a JSON array

I have successfully created a JSON array that I am using to populate a DataTable. The keys in this array correspond to the label names that should go in the thead section of my table, while the values should go in the tbody. This is what my JSON array loo ...

Dynamically update arguments using ajax

Is it possible to dynamically initialize DropzoneJS with a URL obtained through an AJAX call without using async: false? The resulting URL will be dependent on the files argument. $('.class').dropzone({ url: function(files) { var url ...

Transform your sidebar menu into a collapsible dropdown using Bootstrap

My goal is to transform the left sidebar, which currently has a vertical menu built with "nav nav-pills nav-stacked", into a suitable dropdown menu that starts off as closed/collapsed when the screen size is XS (mobile). Here is the starting code snippet: ...

Integrate a text input field with a dropdown menu to create a single component that allows users to either manually input a value or choose

I am searching for a way to create a unified component that combines a textbox and dropdown, allowing users to either input their own value or select one from the dropdown list. Is it possible to achieve this without using autocomplete or combobox features ...

Tips on clearing notices and warnings at the bottom of a PHP questionnaire

Below is the code I am working with: <?php include_once 'init/init.funcs.php'; $_SESSION['pollid'] = (int) $_GET['pollid']; $questions = array(); if (!isset($_SESSION['answering'])) { $result = mysql_query ...

What is the best method for sending a variable using AJAX with a POST request?

I am attempting to send the variable "$var" to "doc.php" and wondering how "doc.php" should read it, as $_POST['$var'] or just $var? Below is the current code I am using: <script src="jquery-1.7.2.min.js" type="text/javascript"> // Is .d ...

Execute a database query to search for patterns using Regular Expressions within the

As I embark on a new project, I find myself questioning my approach before diving in too deep and realizing it may not be the most efficient path. Within the realm of a large company where we develop unofficial tools for internal use, I am faced with limi ...

Is there a way to increase the total of each row by two when a button is clicked?

Looking to enhance the sum of each row by two depending on whether a button is clicked. HTML: <table> <tr> <td> <input type="checkbox" class="prof" name="prof" value="0"> <input class=&quo ...

What could be causing the Ajax code to not activate when clicking or loading?

Appreciate your support. I am venturing into the world of coding MVC and attempting to create a page that will generate a parent-child loop with data sourced from JSON (MenuHandler.ashx). The JSON data has been tested successfully, but there seems to be a ...

Secure User Authentication using HTML and JavaScript Box

In the given code, I am attempting to implement a functionality where a message is displayed next to the select box if it does not have a value of male or female. This message should not be shown if one of these values is selected. However, this feature ...

Node.js and Mongoose not functioning properly in collaboration

Searching for a user based on matching first and last names. router.post('/post/user/search/tag', function (req, res) { function getRegex(_query) { return { $regex: '^' + _query + '|.*' + _query, $optio ...

Is there a way to position two Grid elements to the left and one to the right in Material UI, especially if the first Grid element has a specified width

I'm currently using Material UI and have a Grid layout with three items. The left item needs to have a fixed width of 240px and be aligned to the left. The middle item should be left justified and can have any width, containing buttons that I've ...

Running JavaScript code within views

While dealing with AngularJS, I have an index page that includes a <div ui-view></div>. When a specific URL like #/offers/new is entered, it loads a page such as new-offer.html into the ui-view. In my javascript code block within the index.htm ...

Utilizing a server for seamless communication between a mobile device and a website

Exploring a simple setup idea here: Imagine having a mobile app with a page that contains 4 lines of content (utilizing phonegap for development). The plan is to have a web page where data for those 4 lines can be inputted. Once the information is submitt ...

Efficient ways to enhance CSS animations (including scaling, rotating, and blurring)

In this HTML example, there are two animated pictures - one background and the other an object. Despite using scale and rotate animations, the performance is choppy on full HD monitors, especially in Firefox where it runs at about 20 fps. Initially, jQuer ...

Regular expression for extracting all JavaScript class names and storing them in an array

In my quest to create a straightforward regex, I aim to spot all class names within a file. The catch is that it should identify them even if there's no space preceding the curly bracket. For example: class newClass {...} This should result in ...

What is the best method for assigning a default value to the file input tag in HTML?

Can anyone help me with this code snippet? <input name="GG" type="file" value="< ?php echo $data['image'] ?>"> I was trying to set a default value in the form edit, but it seems to not be working. Does anyone know how to set a defau ...

Is there a way to bypass validation upon button click in ASP.NET Core?

My dilemma involves working with 1 form and 2 buttons, one located within the form element and the other outside of it on a page: <form method="post"> <button asp-page-handler="AddRecord" id="addRecordBtn" class="btn btn-sm btn-secondary ...

Attempting to implement window resizing in a jQuery Cycle slideshow

I am currently experiencing some challenges while trying to execute a JavaScript window resize script on a page that has a jQuery cycle slideshow. The issue I'm facing is that the script resizes the first image correctly upon page load, but it seems t ...

Arrange one array while ensuring the order of the other two arrays remains consistent

data = { "age": [41, 21, 88], "name": ["Rob", "Tom", "Susan"], "color": ["Red", "Blue", "Orange"] } Is there a way to effectively sort the data in these records based on the values of one specific array while maintaining the original data stru ...