Select a row (highlight) from html table and send values onclick of a button

Jacob Chong

Highlight is not function in the web browser. What is the problem of this codes ? Basically, I want to do something highlighted the table row and then post the value of table row to another php page.

test.html

<html>
<head>
<link href="test.css" rel="stylesheet" type="text/css" />
<script src="test.js" type="text/javascript"></script>
</head>
<body>
<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>
    </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>
    </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>
    </tr>
</table>

    <input type="button" id="tst" value="OK" onclick="fnselect()" />
</body>
</html>

test.js

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);
});

test. css

td {border: 1px #DDD solid; padding: 5px; cursor: pointer;}

.selected {
    background-color: brown;
    color: #FFF;
}
Khyati

You don't need fnselect() function

modify your js as :

window.onload = function () {
    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;

        $("#tst").click(function () {
        var value = $(".selected td:first").html();
        value = value || "No row Selected";
        alert(value);
    });
};

also add jquery in your html before the other test.js in head:

and finally make one of the row default selected.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select a row (highlight) from html table and send values onclick of a button

From Dev

Select a row from html table and send values onclick of a button

From Dev

Select multiple rows from html table and send values to a function in javascript

From Dev

How to set the highlight of a table row with jquery from a javascript function call from an onclick in the table row?

From Dev

How to make a button that will send only send values from one table to a row in another table if another cell has a certain value

From Dev

Select an option from a dropdown list by onClick on data-table row

From Java

Highlight differences in row data of HTML table

From Dev

highlight selected row and column on mouseover in html table

From Dev

highlight selected row and column on mouseover in html table

From Dev

Select a row from data table to show radio button value

From Dev

Select row from table in Selenium based on certain text/values

From Dev

How to select row from a table based on two values c#?

From Dev

How to send values from html form to mail in table PHP

From Dev

php/pdo/mysql accessing selected row from a select * in html table

From Dev

How to select a particular value in row from a table in html

From Dev

php/pdo/mysql accessing selected row from a select * in html table

From Dev

Highlight html table cell onclick and copy value with CTRL + C

From Dev

Highlight html table cell onclick and copy value with CTRL + C

From Dev

HTML+JavaScript: How to highlight a row on click of a button in Javascript?

From Dev

JQuery The value 'i' starts from 0 for every button in table but i need the row button onclick to start from a particular index

From Dev

Highlight selected table row

From Dev

Mysql select dynamic row values as column name from a table and value from another table

From Dev

How to remove highlight of button onclick

From Dev

Using the Up and Down arrows keys to scroll (highlight) row in an HTML table

From Dev

Highlight rows in HTML table (hovered over row and preceding rows)

From Dev

using a Jquery ui Slider to highlight html table row/column

From Dev

Column outline overriden by row highlight? (html table, css formatting)

From Dev

How can i select row from table according to column values of row in sql server

From Dev

Send ID of changed row in table (html to JS)

Related Related

  1. 1

    Select a row (highlight) from html table and send values onclick of a button

  2. 2

    Select a row from html table and send values onclick of a button

  3. 3

    Select multiple rows from html table and send values to a function in javascript

  4. 4

    How to set the highlight of a table row with jquery from a javascript function call from an onclick in the table row?

  5. 5

    How to make a button that will send only send values from one table to a row in another table if another cell has a certain value

  6. 6

    Select an option from a dropdown list by onClick on data-table row

  7. 7

    Highlight differences in row data of HTML table

  8. 8

    highlight selected row and column on mouseover in html table

  9. 9

    highlight selected row and column on mouseover in html table

  10. 10

    Select a row from data table to show radio button value

  11. 11

    Select row from table in Selenium based on certain text/values

  12. 12

    How to select row from a table based on two values c#?

  13. 13

    How to send values from html form to mail in table PHP

  14. 14

    php/pdo/mysql accessing selected row from a select * in html table

  15. 15

    How to select a particular value in row from a table in html

  16. 16

    php/pdo/mysql accessing selected row from a select * in html table

  17. 17

    Highlight html table cell onclick and copy value with CTRL + C

  18. 18

    Highlight html table cell onclick and copy value with CTRL + C

  19. 19

    HTML+JavaScript: How to highlight a row on click of a button in Javascript?

  20. 20

    JQuery The value 'i' starts from 0 for every button in table but i need the row button onclick to start from a particular index

  21. 21

    Highlight selected table row

  22. 22

    Mysql select dynamic row values as column name from a table and value from another table

  23. 23

    How to remove highlight of button onclick

  24. 24

    Using the Up and Down arrows keys to scroll (highlight) row in an HTML table

  25. 25

    Highlight rows in HTML table (hovered over row and preceding rows)

  26. 26

    using a Jquery ui Slider to highlight html table row/column

  27. 27

    Column outline overriden by row highlight? (html table, css formatting)

  28. 28

    How can i select row from table according to column values of row in sql server

  29. 29

    Send ID of changed row in table (html to JS)

HotTag

Archive