I made a php page where a table is built from a database. Every cell is a disabled input-text, which is supposed to be activated by the mouse click. Once enabled and modified, pressing the enter key (I'm opened to other solutions, i didn't think about this point yet) should store the new value in the database, show it in the table and disable the field again.
I didn't manage to switch the disabler attribute of the input fields, nor everything else after that (can't do that until the disable/enable function will works properly).
These are parts of code that may help you to understand what I mean.
This is the CSS you could see in the next codes:
<style type="text/css">
.clickable, input[type="text"]:disabled, input[type="number"]:disabled {
cursor: hand;
}
.clickable:hover {
background: #dcd2ff;
}
input[type="text"]:disabled, input[type="number"] {
background-color: rgba(255,0,0,0);
border: 0px;
width: 100%;
height: 100%;
}
</style>
This is the first time I take a look on JS, this is how I think the enabler should be:
<script type="text/javascript">
function edit(cellID) {
var cell = document.getElementById(cellID);
cell.disabled = !cell.disabled;
}
</script>
This is how I built the table:
<table>
<?php
// DB connection + select query
for ($i = 0; $i < $num; $i++)
{
// Getting, for example, $a and $b values
$line_color = ($i % 2 == 0) ? "pair" : "dispair";
echo "<tr class=\"$line_color\">";
echo " <td class=\"clickable\">";
echo " <input id=\"$i-1\" onclick=\"edit('$i-1')\" type=\"text\" value=\"$a\" disabled />";
echo " </td>";
echo " <td class=\"clickable\">";
echo " <input id=\"$i-2\" onclick=\"edit('$i-2')\" type=\"number\" value=\"$b\" disabled />";
echo " </td>";
echo "</tr>";
}
?>
</table>
Here you have "another point of view": http://jsfiddle.net/vL2rw/