Jump to content

Calling Java script experts need help


Bolineni Tiger

Recommended Posts

Hi, I need help; please, can anyone help me?

 

It is a legacy project I am doing enhancement for a page.

 

I have one HTML page with dynamic data table rows and columns.  

 

We have one element, like a dropdown list, in each row in one of the cells. 

 

How can we get the ID of that element?

 

I know how to get an inner text or inner HTML, but I need elements I'd because I need to do some operations on that element.

 

 

Link to comment
Share on other sites

19 minutes ago, HelloNTR said:

html structure post cheyagalara

Hmm it is simple html with 5 columns and N number of rows based on the data.

In each row  in 4th column added one dropdown list and button in 5th column.  

I am writing Java script to get element I'd of dropdowm list on button click.

With that I'd , need to get selected option from dropdown.

Link to comment
Share on other sites

42 minutes ago, Bolineni Tiger said:

Hmm it is simple html with 5 columns and N number of rows based on the data.

In each row  in 4th column added one dropdown list and button in 5th column.  

I am writing Java script to get element I'd of dropdowm list on button click.

With that I'd , need to get selected option from dropdown.

https://stackoverflow.com/questions/26999167/get-id-of-table-cell

first use this to get the id of the table cell on which you clicked

 

https://stackoverflow.com/questions/1904827/how-to-get-selected-option-id

Then use this to fetch the dropdown id

 

Sample code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="chessboard">
    <tr>
       <td id="A8">A8</td>
       <td id="B8">B8</td>
       <td id="C8">C8</td>
    <tr>
    <tr>
       <td id="A7">A7</td>
       <td id="B7">B7</td>
       <td id="C7">C7</td>
    <tr>
    <tr>
       <td id="A6">A6</td>
       <td id="B6">B6</td>
       <td id="C6">C6</td>
    <tr>
</table>

 

 

$("#chessboard td").on("click", function(cell){
    alert(this.id);
     var id = this.id;
     var options = document.getElementById(id).options;
     var id = options[options.selectedIndex].id; 
   var value = options[options.selectedIndex].value;
})

 


 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...