Searching for a dynamically generated table with specific row IDs in JavaScript can be achieved by iterating through

I successfully generated a table with 3 rows without utilizing the traditional table tag. Now I am trying to locate these rows through scripting. Whenever a button is clicked, if any of these rows are empty, I want to trigger an alert prompting the user to enter the missing information. How can I achieve this functionality?

Your suggestions and guidance would be greatly appreciated.

Answer №1

This is a basic illustration that can be tailored to fit your specific needs.

<html>

  <head>

  <title></title>

  <script type="text/javascript">

  window.onload = function(){

  var button = document.getElementById('check_rows');

  var tableDiv = document.getElementById('content');

  var tableHTML = "<div id='mytable'><div id='row_one'>Content for row one</div><div id='row_two'></div><div id='row_three'></div></div>"

  tableDiv.innerHTML = tableHTML; 

  button.onclick = function(){

   if(document.getElementById('row_one').innerHTML == '') alert('Row 1 is empty');

   if(document.getElementById('row_two').innerHTML == '') alert('Row 2 is empty');

   if(document.getElementById('row_three').innerHTML == '') alert('Row 3 is empty');

    }

 }

  </script>

  <style type="text/css">

  #mytable {

    width: 305px;

    height: auto;

    border: 1px solid black;

    padding:5px;  

    margin-top:10px;

  }

  #mytable div{

    width: 290px;

    height: 100px;

    margin:5px;

    border: 1px solid red; 

  }

  </style>

  </head>

  <body>

  <input type="button" value="Check Rows" id="check_rows"/>

 <div id="content">  

</div>

  </body>

</html>

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

A helpful guide on how to separate text using Java Script and the "/" character

Just diving into the world of JavaScript and encountering some challenges with splitting text. The string that needs to be split looks like this: mobile)/index.m3u8 The desired output should be: mobile and index.m3u8 I attempted to use .split("&bso ...

Implementing click events for each row in a table representing data (using JQuery)

Recently, I began my journey with javascript and decided to develop a new application that involves using a dynamic data table. The data for this table is generated dynamically through a set of information referred to as dataSet. However, I encountered an ...

Exploring the world of Ajax with jQuery

Could someone help me figure out how to integrate Ajax into my PHP code so that the content can load dynamically? Currently, it looks something like this: First, a user selects a category: <li><a href='?genre=sport'>Sport</a>& ...

The variable "$" has not been defined in the Mocha Chai test script

I am currently in the process of writing a unit test case for a JavaScript function. The function is located within a .js file, which I have loaded into a test.js file to run. To run the tests, I use the command npm test test.js Within my test script, ...

React component closes onBlur event when clicked inside

I recently developed a React component using Material UI which looks like the code snippet below: <Popper open={open} anchorEl={anchorRef.current} onBlur={handleToggle} transition disablePortal > <MenuList autoFocusItem={open}> ...

What is the best way to instruct Maven to package my JavaScript project as a war file from the root directory?

Hey everyone, I'm still searching for a reliable method to package a javascript project. Typically, the default approach is to simply release it to the docroot of your appserver, which I find quite unpleasant. My simple node.js javascript project, w ...

After combining two files in browserify, the error message "XXX.foo is not a function" appeared

When using browserify to bundle two JavaScipt files into one with the command: browserify X1.js X2.js --standalone XXX > bundle.js The file X1.js contains a function like this: function foo() { console.log("something") } And it is being exported i ...

How can I execute a different seed file using Sequelize-cli before running the main seed file?

I recently created a seeder file using sequelize-cli to bulk insert data into a MySQL database, and everything is working perfectly. However, one of the fields I am inserting (userId) requires a value that is already present in another table called User. ...

Extracting Values from JSON Array using Form Input Text

After designing a form for my web application, I encountered a situation where some fields needed to be populated with values from a JSON array retrieved from the treatment table in the database. {"treatment":[ { "id" : 1, "name" : "Leg Training" }, ...

Troubleshooting broken links on a multi-page website built with node.js and ejs

I am encountering some difficulties with my multi-page website created in node.js/ejs. I suspect that the issue lies within the routing mechanism, although I have double-checked my routes and they seem to be configured correctly. The problem arises when I ...

Audio issues plaguing audio playback on Discord

After spending two exhausting days, I am still trying to figure out what is going on. I am currently working on a Bot for my Discord Channel that should play an audio.mp3 file when a specific command, like !laugh, is entered. However, despite trying variou ...

Rendering recursively within React Context using an array of objects

I have developed a React Native code that includes a Markdown editor capable of parsing text and extracting information related to Headers. My goal is to construct a menu showcasing the headers, allowing users to click on them and navigate directly to the ...

In JavaScript, the HTML <select> onclick event is fired when the down button of the scrollbar is clicked

I have encountered a problem while trying to use the onclick() event of the Select object. The function is triggered and executes correctly, but it also gets executed when clicking on the scroll bar's down button. This results in users not being able ...

Troubleshooting issue with React mapping an array of items in a modal window

My state implementation is working perfectly fine, except for a minor issue with the modal window. Within the state, I have utilized objects that are normally displayed (you can refer to the screenshot here). Please pay attention to the "Open modal" butt ...

Is it possible to transform this nested promise into a chain instead?

This situation is just a scenario | then (items) | then (items, actions) getItems() | getActions(for:items) | apply(actions -> items) :promise | :promise | model <= items | | :sync ...

Produce a vue attribute

I am looking to display a property in my component. My template includes: <v-flex v-for="c in components"> <component :is="c.component" v-bind="c.prop"></component> </v-flex> And in the script: ... mounted(){ ...

Looking to implement multiple databases with node using MongoDB and Mongoose technology?

Hey there, I'm facing a small technical issue and need some help. I have a database named "Company" with two columns: name and DBname. Additionally, I have multiple Company databases and I want to retrieve company data based on the Company DB. In my ...

What is the most effective method for incorporating real-time UI updates similar to the "new answer" notifier on Stack Overflow?

How should web applications be designed to handle realtime UI updates? For instance, how do you manage prompt notifications when another user submits an answer while you are answering a question on a platform like SO? Additionally, if every page on your ...

Creating a specific ng-init condition for introducing new elements into the scope

Using ng-repeat, I am generating a series of todo items within div elements. My goal is to automatically apply the "editing = true" styling to these newly created items and if possible, focus on them as well. <div class="item" ng-class="{'editing- ...

GlideJS is experiencing a flashing issue on the first slide

Is anyone else experiencing a flashing issue when changing slides in the slider periodically? Specifically, the first slide flashes when transitioning from the first to the last slide. This bug seems to be isolated to Chrome only. Interestingly, I've ...