I have this table
function highlight(e) {
if (selected[0]) selected[0].className = '';
e.target.parentNode.className = 'selected';
}
var table = document.getElementById('table'),
selected = table.getElementsByClassName('selected');
table.onclick = highlight;
function fnselect(){
var $row=$(this).parent().find('td');
var clickeedID=$row.eq(0).text();
// alert(clickeedID);
}
$("#tst").click(function(){
var value =$(".selected td:first").html();
value = value || "No row Selected";
alert(value);
});
.selected {
background-color: brown;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="table">
<tr>
<td>1 Ferrari F138</td>
<td>1 000€</td>
<td>1 200€</td>
<td>Model monopostu stajne Scuderia Ferrari pre sezónu 2013</td>
<td>1</td>
<td>F138</td>
<td>Klik pre detaily</td>
<td><select name="sel" id="sel" >
<option value="1">Seleccion</option>
<option value="2">123</option>
<option value="3">456</option>
</select>
</td>
</tr>
<tr>
<td>2 Ferrari F138</td>
<td>1 000€</td>
<td>1 200€</td>
<td>Model monopostu stajne Scuderia Ferrari pre sezónu 2013</td>
<td>1</td>
<td>F138</td>
<td>Klik pre detaily</td>
<td><select name="" id="hola">
<option value="1">Seleccion</option>
<option value="2">123</option>
<option value="3">456</option>
</select>
</td>
</tr>
<tr>
<td>3 Ferrari F138</td>
<td>1 000€</td>
<td>1 200€</td>
<td>Model monopostu stajne Scuderia Ferrari pre sezónu 2013</td>
<td>1</td>
<td>F138</td>
<td>Klik pre detaily</td>
<td><select name="" id="hola">
<option value="1">Seleccion</option>
<option value="2">123</option>
<option value="3">456</option>
</select>
</td>
</tr>
</table>
<input type="button" id="tst" value="OK" onclick="fnselect()" />
When I click the button OK
, it brings me only the first value of the selected table. I am trying to make it fetch all the values including the select value.
For example, so that it does not bring me all the data of the select, which they are 123
, and 456
show me only the selected one. and not the 2 values
In the jquery selector you are stipulating that it takes the first
td
solo...So you should remove that and change the
html
to atext
But for the selected dropmenu to take you, you cannot take the entire line and that's it. You have to go iterating all the
td
with the functioneach()
and concatenating itstext()
until you find onetd
that has aselect
Then you take the
option
one that is selected and from there itstext
.