简体   繁体   中英

get value of the selected checkbox from matrix table

I have designed a matrix table using html in asp.net web form so I want if user click the checkbox immediately display the name of the selected row and also of the selected column. The output it should look like this : Chlor-Alkali Relationship see the screenshot below but it return the row index and column index.

在此处输入图片说明

here is the code below:

You can get the value of the checked inputs using document selector and checked attribute:

function myFunction() {
  // get all checkboxes
  const checkBoxes = document.getElementsByClassName("selectableType");
  var result = "";

  // iterate over them
  for (var box = 0; box < checkBoxes.length; box ++) {

    // check if single checkbox is checked
    if (checkBoxes[box].checked === true) {

      // and do your needed magic here :D
      console.log(">", checkBoxes[box].value);
      result += checkBoxes[box].value + "\n";
    }
  }

  // just an example to show results
  alert (result === "" ? "No result" : "Selected inputs are\n" + result);
}

Check here a working example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM