I need to check the entire table if there is a value(RESERVED) on column 1 and return the value of cell 0 of that row where the value was found.
Basicly click on a button, run the function and return the value of cell 0 of the row where the value(REVERVED) was found.
I like to do this with plain javascript not jquery if I could.
The function below works if I physically click on that row.
<input type="button" value="☑️ check if RESERVED exists" onclick="findValueInRow()"> //
<br>
<br>
<table id="table2">
<thead>
<tr>
<th>ID</th>
<th>Contact</th>
<th>Country</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>2</td>
<td>RESERVED</td>
<td>Mexico</td>
</tr>
<tr>
<td>1</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>3</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>4</td>
<td>RESERVED</td>
<td>Canada</td>
</tr>
<tr>
<td>5</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
</body>
function findValueInRow()
{
table = document.getElementById("table2");
for(var i = 1; i < table.rows.length; i++)
{
table.rows[i].onclick = function()
{
// get the selected row index
rIndex = this.rowIndex;
var produtcID = this.cells[1].textContent;
//check to see if value RESERVED exists in the table
if(produtcID == "RESERVED" )
{
alert(this.cells[0].textContent);
}
else{
//my other code if the value is not found
}//end else
};
}
}