Passing an array to jquery dialog

Firstly merry Christmas to one and all. Now here is my problem. I am using a checkbox to gather values from a Datatable and into an array. What is happening is that only the first value is being evaluated when passed to dialog. I am not sure if I have to use $.each function in the ‘rowClk’ event or some other method.

I would be grateful if someone could offer some help as to what i need to do in order to process all items. Many thanks

$(function() {
$(document).on('click', '#rowChk', function() {

  currentRows = $(this).closest("tr");
  rackid = currentRows.find("td:eq(0)").html();
  rackdept = currentRows.find("td:eq(4)").html();
  rackitem = currentRows.find("td:eq(8)").html();
  info = [];
  info[0] = rackid;
  info[1] = rackdept;
  info[2] = rackitem;
$(document).on('click', '#rowClk', function() {

Nothing obvious seems to be jumping out from the code that you posted.

Can we take a look at the webpage itself, as a more detailed investigation can then take place.

Hi paul
Sorry only working localhost. What I am trying to is:

  1. Get the value from the table
  2. Put them into an array
  3. Pass this array to dialog

However, I am only getting the first value so I am guessing I may need a $.each loop somewhere in the #rowClk event? I am fairly new to js and jquery so learning as I go. Many thanks

This piece requires further clarification.

  • Is the rowClk event only showing the first item (that being the rack id) from the info array?
  • Or, is only the first table row being shown, with all items from that row being shown?

It is showing all 3 items from the first row like so.


Thank you. JavaScript doesn’t like it when unique identifiers are not unique.

I recommend that you use class names for those instead, which are allowed to not be unique.

Sorry paul. Can you clarify with an example please. Thanks

With JavaScript, each id attribute is supposed to be unique.
When you ignore that and use the same id name with multiple identifiers, only the first one is ever picked.

However, jQuery has some ways around that, so my initial thoughts on the matter don’t seem to be relevant in this case. Which means, that not enough information is yet available to be able to assist any further.

Can you put together a demo page that we can explore, so that a more detailed investigation can occur?

I’ll try. Thanks. What is the usual way get selected checkboxes into an array?

Here’s the usual way that I do it:

const checkboxes = document.querySelectorAll("[type=checkbox]");
const isChecked = (checkbox) => checkbox.checked;
const checkedCheckboxes = checkboxes.filter(isChecked);

What do I put in console.log to see value of array. I have tried various vars but nothing prints. Thanks

From what I’ve seen, that can’t be done because it’s out of scope. There might be some other way, but I am awaiting a demo before further such information might be divulged.

OK Paul. I’ll try and put something together and report back. Cheers

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.