简体   繁体   中英

How to add the value to a specific row data in table(Parent) from child page using javascript?

I have two pages First.html and Second.html. In Second.html i have one search button that redirect to second.html and once I choose the value it will populate the value in first.html. But the problem is in first.html the table has two id ="major". Based on the search button it will populate the value in the particular major box. How to achieve this ?

You can access two different elements with same id like this:

var table=$("table#major");
var inputelement=$("input#major");

As the comment suggested, IDs should be unique in your HTML. To determine which row you want to manipulate, use the ID from the table and use the table's rows collection...

document.getElementById("Major").rows[rowNumber].cells[1].children[0].value;

...rowNumber will probably need to be manipulated to ensure you are on the correct row. With your code, the first row you care about is row 2.

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