Creating dynamic dropdown menus using JSON files in jQuery mobile is a useful technique for enhancing user experience on

I am working with a massive table (8 MBytes) that I need to filter using a small JavaScript application.

The process works as follows:

  1. Countries
  2. Regions
  3. Skills

I want the user to select one country, one region, and multiple skills as filters. Based on this information, I aim to display a table with relevant data. My challenge lies in integrating the JavaScript functionality with the HTML content. I am unsure how to dynamically insert information from an array instead of hardcoded values. (Eventually, I will replace arrays with JSON files)

Thank you for your assistance.

var country = [
  ["Australia", "AU"],
  ...
  ["Thailand", "TH"]
  ];
var skill = [
  ["AU", "Queensland", "Skill 1"],
  ["AU", "Queensland", "..."],
  ["AU", "Queensland", "Skill n"],
  ["AU", "Western Territory", "Skill 1"],
  ...
  ];
  
  
  
 function initCountry(){
   var CountryValue = "AU";
 }
  
  
  
  
  
  function startup() {
     initCountry();
     initRegion();
     initSkill();
  }
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" id="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <link rel="stylesheet" href="cs/jquery.mobile.css" />
    <link rel="stylesheet" href="cs/basis.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.mobile.js"></script>
</head>
<body onload="startup()">
<form id="FilterForm" name="FilterForm">
 <label for="select-custom-20">Countries</label>
    <select name="select-custom-20" id="select-custom-20" data-native-menu="false">
<option value= "AU">Australia</option>
...
<option value= "TH">Thailand</option>
    </select>
</div>
<div class="ui-field-contain">
    <label for="select-custom-19">Region:</label>
    <select name="select-custom-19" id="select-custom-19" multiple="multiple" data-native-menu="false">
        <option>Choose options</option>
        <option value="1" selected="selected">Average</option>
        <option value="2">Region 1</option>
        <option value="3">Region 2</option>
        <option value="4">...</option>
<option value="5">Region n</option>
    </select>
</div>
<div class="ui-field-contain">
    <label for="select-custom-19">Skill:</label>
    <select name="select-custom-19" id="select-custom-19" multiple="multiple" data-native-menu="false">
        <option>Choose options</option>
        <option value="A" selected="selected">Average</option>
        <option value="1">Skill 1</option>
...
        <option value="T">Skill n</option>
</select>
</div>
</form>
<table>
<tr>
<td>
Data depending on the filter
</td>
</tr>
</table>
</body>
</html>

Answer №1

Add an identifier to your table:

<table id="filteredTable" data-role="table"  data-mode="reflow" class="ui-responsive">
  <thead>
    <tr>
      <th>Country</th>
      <th>Region</th>
      <th>Skill</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

After obtaining the filtered list of skills, generate the HTML content using a JavaScript loop, clear the table, and add the new content:

  var rowsHTML = '';
  for (var i=0; i< skill.length; i++){
    rowsHTML += '<tr>';
    rowsHTML += '<td>' + skill[i][0] + '</td>';
    rowsHTML += '<td>' + skill[i][1] + '</td>';
    rowsHTML += '<td>' + skill[i][2] + '</td>';
    rowsHTML += '</tr>';    
  }  
  $("#filteredTable tbody").empty().append(rowsHTML);

Check out the DEMO here!

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

Two interconnected queries with the second query relying on the results of the first

I am currently facing a challenge in my Phonegap (Cordova) application where I need to display a list of items, each requiring an additional query. Let me simplify it with an example scenario. Imagine a student can be enrolled in multiple courses and a co ...

Utilizing Lodash in TypeScript to merge various arrays into one cohesive array while executing computations on each individual element

I am working with a Record<string, number[][]> and attempting to perform calculations on these values. Here is an example input: const input1 = { key1: [ [2002, 10], [2003, 50], ], }; const input2 = { key ...

Transforming an array into a JSON object

I currently have an array structured like this: [ 'quality', 'print-quality: 4', 'x-dimension', 'Value: 21590', 'Value: y-dimension', 'Value: 27940', 'Value: ', 'Valu ...

The dropdown in MaterializeCSS does not display any data retrieved from VUE

Good evening. I am currently utilizing VUE along with MaterializeCSS. I have been trying to populate a selection menu without success. Although I am receiving the data from the database correctly, the options in the select tag remain blank when using V-F ...

Why does my React.js application still display outdated data from my Express server even after refreshing the webpage?

I have been working on a website using React.js and Express.js, following an online example to set up the basic code. I encountered an issue where the frontend did not update when I made a minor change to the array sent by Express.js. Express - users.js f ...

Retrieve class property in Angular by its name

How can I retrieve an array from a class like the one below without using a switch statement, dictionary, or other collection to look up the name passed into the method? export class ProcessOptions { Arm = [{ name: 'Expedited Review ("ER") ...

Ways to conceal the scroll bar upon the initial loading of a webpage

Recently, I created a single-page website consisting of 4 sections. The client has specific requirements that need to be fulfilled: The scrollbar should not be visible when the page loads. Once the user starts scrolling past the second section, the scrol ...

Expanding Gridview Width within a Container in ASP.Net: A Step-by-Step Guide

https://i.stack.imgur.com/ZaJE7.jpg After viewing the image above, I am facing a challenge with stretching and fixing a gridview to contain the entire div where it is placed. The issue arises when the gridview adjusts automatically based on the content&ap ...

Guide to assigning values to Input<input> and Select <select> elements using Javascript

I am looking to automatically set values in an input or select tag based on certain conditions defined in the JavaScript code below. However, I am facing an issue where the data does not get reflected in the database upon submitting. Any suggestions or cod ...

Discover the outcome of two asynchronous ajax requests using XHR's onprogress event-handler

My current challenge involves seeking out images within an ajax request response and extracting the src URL for utilization in another ajax request. I am aiming to monitor the loading progress of each image and display the resulting progress in a designat ...

Tips for organizing a Material UI DataGrid table effectively while keeping the total sum rows within the DataGrid unaffected

Check out my codeSandbox link here: https://codesandbox.io/s/making-sum-of-column-in-datagrid-mui-zjzfq6?file=/demo.js I've noticed that when I sort by ascending, the subtotal, total, and tax rows move up, but when I sort by descending, they move dow ...

What is the process for utilizing an Angular service within a view expression?

Angular guidelines suggest utilizing Angular services and expressions: It is recommended to use services like $window and $location in functions called from expressions. These services offer a way to access global variables that can be easily mocked. - ...

Unlock the Potential of Azure Open Data With PHP

I am currently exploring the functionality of a webservice provided by RDW. This particular webservice allows users to retrieve information about a car by inputting its license plate number. Below is the link that I have been utilizing for this purpose. h ...

Unable to begin the previous project on my Mac, but it functions properly on Windows

After running npm i, I encountered the following error message which I am unsure how to resolve. I tried reinstalling Node.js, Python, and Pyenv, but the issue persists. Interestingly, the same version of Node.js on Windows runs the project without any p ...

passing parameters via routes

I've been working on passing parameters through the URL using this code, but it doesn't seem to be functioning properly. I suspect that the issue lies in the "get(\users:id)" part, but I'm unsure of the correct way to do it: $.ajax ...

The React DevTools display components with the message "Currently Loading."

I am currently facing an issue with debugging some props used in my React application. When I try to inspect certain components, they display as "Loading..." instead of showing the normal props list: https://i.sstatic.net/RtTJ9.png Despite this, I can con ...

Incorporate various style components to enhance the appearance of an item in ExtJS

I'm attempting to add ellipsis to an item created by ExtJS. My goal is to only modify this item without adding any additional CSS files. After researching, I discovered there is a "style" parameter that accepts CSS styles and attempted the following: ...

When attempting to connect to the MongoDB cloud, an unexpected error arises that was not present in previous attempts

npm start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="650800170b4816001713001725544b554b55">[email protected]</a> start > nodemon index.js [nodemon] 3.0.2 [nodemon] to restart at any time, enter ...

What is the most effective way to divide input elements into an array in Angular?

How can I bind an input value to an ng-model as an array? For example, if I enter one, two, three, I want the resulting model to be [ "one","two","three" ]. Currently, this is my approach: <input type="text" ng-model="string" ng-change="convertToArra ...

What strategies can be employed to reduce the need for numerous if-else statements in my JavaScript code?

In my input form, users have the ability to make edits. I need to send only the data that has been changed by the user. Currently, I am repeating the same lines of code multiple times to compare and determine what data needs to be sent. Is there a more e ...