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

The JavaScript code that added links to the mobile menu on smaller screens is no longer functioning properly

I recently created a website with a mobile navigation menu that should appear when the browser width is less than 1024px. However, I used some JavaScript (with jQuery) to include links to close the menu, but now the site is not displaying these links and t ...

AngularJS version 1.5.11 experiencing issues with ng-repeat functionality

Having an application built on angularJS v1.5.11, I encountered a major issue while attempting to use ng-repeat in a table format like below: <tbody> <tr ng-repeat="score in data.result"> <td ng-repeat="item in score"> {{ item }} & ...

What is the best way to merge two JSON objects linked by a foreign key in Angular?

Looking to display data from two JSON objects in a table, connected by a foreign key. The first set of JSON data is as follows: $scope.items = [ {status_id: 1, type: 1}, {status_id: 2, type: 2}, {status_id: 1, type: 3}, {status_id: 1, typ ...

How to bypass validation for required input in jQuery validate plugin

As an example, consider the <input name="surname" id="surname" type="text">. Sometimes I want to hide this input and make it non-required. My current workaround is to set a value such as "some value" when hiding the input, and then remove this value ...

Unlock the potential of AngularJS services with this innovative design strategy

I am currently developing an AngularJS client application that will communicate with a REST server. To handle the interaction between the client and server, I have decided to use the $resource abstraction from AngularJS. Each resource is being written as ...

Unfortunately, the input type number does not allow for the removal of decimal points

I need assistance with modifying the HTML code below. I want to remove the decimal point from the input field. Could anyone please provide instructions on how to accomplish this? <input type="number" min="0" step="1" ng-pattern="/^(0|[1-9][0-9]*)$/" ...

Exploring the concepts of AngularJS directives and resources

I've been experimenting with angularjs and rest service calls to display specific data sets, but I'm encountering challenges with custom directives and resources. Currently, I have a custom directive that loads a list of comments in an applicati ...

Having trouble with the "Corrupted @import" error during grunt build?

As I embark on my journey to create my very first Angular application, I have encountered a roadblock. Using Yeoman and angular-generator, everything seemed to be running smoothly with "grunt serve." However, when I attempted to execute "grunt build," the ...

Experience the power of Vue Google Chart - Geochart where the chart refreshes seamlessly with data updates, although the legend seems to disappear

I have integrated vue google charts into my nuxt project. Whenever I select a different date, the data gets updated and the computed method in my geochart component correctly reads the new data. However, the legend or color bar at the bottom does not funct ...

Can you tell me what this code on Facebook is for?

Upon inspection of Facebook's activity in my browser, I stumbled upon the following code snippet: for (;;);{"t":"refresh"} Attempting to decipher its purpose reveals an infinite loop. Can you identify its function? ...

Synchronizing two navigation menus on a single-page application website

Let me start by saying that I specialize in back end development and am facing a specific challenge with building a website that includes two navigation menus. The main navigation menu features links like Home, while the sub-navigation menu includes option ...

Struggling to align the image elements accurately

I am aiming to create a layout similar to the image displayed below. To be more specific, my goal is to scatter smiley faces randomly within a 500px area while also having a border on the right side of the area. However, with the current code I'm us ...

Upon clicking the link, the JavaScript functionality failed to activate

When I click on a link and try to add a class, it's not working. I want to create a "modal" div. Here is the PHP/HTML code: <?php if(isset($_GET['ido'])) { ?> <div id="modal" class="modal" style="background: blue; width: 1 ...

Utilizing jQuery DataTables for data fetched via Ajax calls

I am trying to showcase a specific collection of data from my MongoDb in a table using the jQuery DataTables plugin. However, I encountered an error message which says: Requested unknown parameter '0' for row0, column 0. For more information ...

Arrange the objects in the array in React based on their time and date of creation

As a newcomer to the world of React.js and Redux, I am faced with an array of objects structured like this: quizList = [ { createdDate : 1543314832505, id:5bfd1d90d4ed830001f589fc, name:'abc'}, { createdDate : 1543314152180, id:5bfd1ae8d4ed83000 ...

Javascript encountering compatibility issues with certain versions of Internet Explorer; employing browser detection workaround

Unfortunately, Internet Explorer is causing issues when trying to execute this script (specifically the 'else' part). Despite numerous attempts, I have been unable to resolve it. $(document).ready(function(){ if (navigator.appName != "Micros ...

Difficulty with CasperJS multi-select functionality

I am currently attempting to utilize CasperJS for choosing both options in a multiple select within an HTML form: <select id="bldgs" name="bldgs" multiple="multiple" size="6" autocomplete="off"> <option value="249759290">Southeast Financia ...

Implement a jQuery loop that utilizes the fadeIn effect

Currently, I have a basic jQuery function in place to generate a small image slider: function gridhover() { $(".grid-item .slide-image").each(function(index) { $(this).delay(400*index).fadeIn(300); }); } $( ".grid-item" ).hover(function() ...

Error encountered with NodeJS Express Module: TypeError - Unable to access property 'finished' as it is undefined

Recently, I've been working on creating an API that can extract text from a website based on specific keywords. To achieve this, I utilized Selenium to load the site and retrieve the text. However, I encountered an issue with sending the extracted tex ...

Sequential execution not functioning properly in NodeJS Async series

Here is the code snippet I am working with: var async = require('async'); var rest = require('restler'); async.series([ function(callback){ rest.get('https://api.twitter.com/1.1/statuses/mentions_timeli ...