employing rowspan functionality within a JavaScript application

How can I achieve a table layout where the first two columns are fixed for only one row and the remaining rows are repeated 7 times? Additionally, is there a way to make the bottom border of the last row thicker? Check out the expected table for reference.

function display() {

  var tableRef = document.getElementById('myTable1').getElementsByTagName('tbody')[0];

  for (var i = 0; i < 7; i++) {
    var rowsAdd = tableRef.insertRow();

    // Insert cells with input fields
    ...
   
  }


}
#myTable1 {
  border-collapse: collapse;
  width: 100%;
}

#myTable1 th {
  background-color: #009999;
  color: black;
}

.table-fixed {}

#myTable1 .tbody1 {
  height: 200px;
  overflow-y: auto;
}

#myTable1 thead,
.tbody1 {
  display: block;
}
<table class="table table-striped table-bordered table-fixed table-hover table-condensed" style="width: 1200px;" id="myTable1">
  <thead>
    <tr>
      <th rowspan='2'>Date Comm.</th>
      <th rowspan='2'>Drug</th>
      <th rowspan='2'>Dosage</th>
      <th rowspan='2'>Route Of Admin</th>
      <th rowspan='2'>Ordered By</th>
      <th rowspan='2'>Time</th>
      <th rowspan='2'>Delete</th>


    </tr>

  </thead>
  <tbody class="tbody1">
  </tbody>
  <tr id="hiderow">
    <td><button onclick="display()"></button></td>
  </tr>

</table>

Answer №1

After some modifications, here is the updated display function:

    function updateDisplay() {

        var tableReference = document.getElementById('myTable1').getElementsByTagName('tbody')[0];

        for (index = 0; index < 5; index++) {
            var rowToAdd = tableReference.insertRow();
                if (index<1)
            {
                var newCell = rowToAdd.insertCell();
            newCell.innerHTML="<input form ='forma' class= 'form-control input-sm' type='text' id = 'time' name= 'time' required>";
            newCell.rowSpan=6;
            newCell.style.width = '60px';

                var newCell = rowToAdd.insertCell();
            newCell.innerHTML="<input form ='forma' class= 'form-control input-sm' id = 'oraltype' name= 'oraltype' required>";
            newCell.rowSpan=6;
            newCell.style.width = '40px';
            }
                var newCell = rowToAdd.insertCell();
            newCell.innerHTML="<input form ='forma' class= 'form-control input-sm' type='text' id = 'oralamt_" + index + "' name= 'oralamt' required></td></tr>";
            newCell.style.width = '65px';

            newCell = rowToAdd.insertCell();
            newCell.innerHTML = "<input form ='forma' class= 'form-control input-sm' id = 'oralcommence_" + index + "' name= 'oralcommence'  required>";
            newCell.style.width = '55px';

            newCell = rowToAdd.insertCell();
            newCell.innerHTML = "<input form ='forma' class= 'form-control input-sm' id = 'amtgiv_" + index + "' name= 'amtgiv' required>";
            newCell.style.width = '65px';

            newCell = rowToAdd.insertCell();
            newCell.innerHTML = "<input  form ='forma' class= 'form-control input-sm' type='text' id = 'urine_" + index + "' name= 'urine' required>";
            newCell.style.width = '50px';

            newCell = rowToAdd.insertCell();
            newCell.innerHTML = "<input form ='forma' class= 'form-control input-sm' type='text' id = 'remarks_" + index + "' name= 'remarks' required>";
            newCell.style.width = '40px';

            newCell = rowToAdd.insertCell();
            newCell.innerHTML = "<i class='fa fa-trash-o' style='font-size:20px' onclick='deleteRow(this)'></i>";
            newCell.style.width = '40px';


        }


    }

Check out the updated 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

Setting up additional requirements in a subfolder within play.js

Seeking assistance with an issue in play.js on Sandbox. Attempting to install a dependency but my package.json is not located in the root folder; it's stored within a folder named frontend. How can I install them when the package.json is inside that f ...

A guide to using Angular to emphasize text based on specific conditions met

Currently, I am developing a testing application that requires users to choose radio type values for each question. The goal is to compare the selected answers with the correct answers stored in a JSON file. To achieve this, I have implemented an if-else ...

I am looking to showcase the information from two separate collections

I am looking to display data from two separate mongoose collections. I have a Member collection and a Property collection. Below is my code for fetching the data: const Property = require('../models/propsSchema') const Members = require(&apo ...

Incorporate a background image into input fields with Autofill on mobile browsers to override the default yellow background that obscures them

It is common knowledge that modern browsers apply a less than appealing yellow background to text fields when Autofill is used by visitors. A helpful workaround is known to override the default text and background colors, and even incorporate a background ...

Arrange a row of fifteen child DIVs in the form of bullets at the bottom of their parent DIV

Currently, I am working on customizing a slider by adding bullets. My goal is to create a gradient background for the parent div containing these bullets. However, when I try to increase the height of the parent div, all the bullets align themselves at the ...

Having trouble with Angular's ng-tags-input? Are you getting the error message "angular is not defined"? Let

I recently created a new Angular project using the following command: ng new "app-name" Now, I'm attempting to incorporate ngTagsInput for a tag input feature. However, every time I try to build and run my app, I encounter an error in my browser con ...

I want to utilize a select drop-down menu for navigating between pages in my pagination, breaking away from the traditional method of using <a> tags

I have a select dropdown that is dynamically generated for navigation to other pages within the script. It lists the number of pages available for navigation. However, after selecting a page and loading it, the dropdown does not stay selected. I've tr ...

Tips for extracting unique values from two arrays and returning them in a new array using JavaScript

Hello, I need assistance with combining two arrays. Array a contains [1,2,3] and array b contains [2,5]. I would like the result array to only include elements that are unique between the two arrays, such as [5]. Can you please provide guidance on how to ...

Utilizing LessCss for color transparency and variable declarations with @vars

I'm attempting to create a function using LessCss, but I am encountering an issue: .transparent-border (@alpha:.15, @color:'0,0,0', @type: solid, @size:1px) { @val: @size @type rgba(@color, @alpha); border: @val; } The problem er ...

Angular UI Bootstrap collapse directive fails to trigger expandDone() function

I am currently utilizing UI Bootstrap for Angular in one of my projects, and I have developed a directive that encapsulates the collapse functionality from UI Bootstrap. Here is how it looks: app.directive( 'arSection', ['$timeout', fu ...

The unexpected behavior in React's reconciliation process: What is causing the state to remain unchanged?

While exploring the React documentation, I came across an interesting example of resetting state: here To better understand it, I created different sandboxes to experiment with. However, I am struggling to reconcile what I observe in each of them. Each s ...

Having trouble mocking Node fs Modules using Sinon

I am facing an issue with mocking the promises methods of the node fs module in my code. When my appData.ts file is executed, it calls the actual fs.promises.mkdir method instead of the mock function defined in \__tests__/appData.test.js. I suspect ...

Enhance the background property in createMuiTheme of Material-UI by incorporating additional properties using Typescript

I've been attempting to include a new property within createMuiTheme, but Typescript is not allowing me to do so. I followed the instructions provided here: https://next.material-ui.com/guides/typescript/#customization-of-theme I created a .ts file ...

What is the correct way to utilize a variable as a parameter in React Query while employing the axios.request(options) method?

I'm currently working on a React Query component with the following structure: function test () { const [var, setVar] = useState("") const options = { method: "GET", url: "https://api.themoviedb.org/3/search/tv" ...

Struggling to make the DataTables.net Bootstrap 5 example function properly

I'm currently working on familiarizing myself with the styling example for Datatables.net using Bootstrap 5, which can be found at https://datatables.net/examples/styling/bootstrap5.html. I've followed the code provided in the example closely, bu ...

The Next.js client-side JavaScript application experiences unforeseen disruptions without generating any console errors

My server is responsible for constructing HTML from a JSON response: { content: "<div id=\"_next\">...</div>...<script src=\"...\"></script>" } This is how my Node server handles the data: const output = "&l ...

The required validator in Mongoose is not being triggered by the function

I'm trying to use a function as a validator in a mongoose schema, but it doesn't seem to work if I leave the field empty. The documentation states: Validators are not run on undefined values. The only exception is the required validator. You ...

What is the best way to load $cookies into an Angular service?

After defining an Angular service where I need to access a cookie, I noticed that the $cookieStore is deprecated and that it's recommended to use $cookies instead. This is how my service is set up: 'use strict'; var lunchrServices = angul ...

What are the common practices for UI bindings in JavaScript and AJAX applications?

Background Information Currently, I am in the process of developing a traditional web application with most forms operating through AJAX. I am facing challenges in connecting the user interface to the model. As of now, I have to explicitly: Specify the ...

The functionality of jQuery smooth scrolling to an anchor is only effective when the page is at the top and there is

Currently, I am working on designing a simple one-page website featuring a fixed menu that smoothly scrolls to specific sections on the page upon clicking the menu items. However, I have encountered an issue where the scrolling works perfectly only when t ...