As far as I know, value is being used as HTML input attribute.
<form action="form_action.asp" method="get">
<input type="submit" value="Submit form" />
</form>
However, I was wondering, is it a correct practice, that I can use it in other HTML attributes, to act as hidden value?
For example, for each table row, I would like to tag it with a unique ID, as the unique ID in SQL database. However, at the same time, I would also like to hide the unique ID from end users.
Here is the technique I have been using.
<html>
<head>
<title>
XXX
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.delete-button').click(function() {
var clicked = $(this);
alert(clicked.parent('tr').attr('value'));
});
});
</script>
</head>
<body>
<table style="border-style:none">
<tbody>
<tr>
<th>Server Name</th>
<th>IP Address</th>
</tr>
<tr style="border-style:none" value="ROW ID 1">
<td class="edit">Yahoo Server</td>
<td class="edit">196.168.0.1</td>
<td class = "delete-button" style="border-style:none"><a href="">DELETE</a></td>
</tr>
<tr style="border-style:none" value="ROW ID 2">
<td class="edit">Google Server</td>
<td class="edit">196.168.0.2</td>
<td class = "delete-button" style="border-style:none"><a href="">DELETE</a></td>
</tr>
</tbody>
</table>
</body>
</html>
Since I didn’t do HTML and JavaScript quite often, I was wondering, whether the above is a correct and common used technique?
With strict HTML4/XHTML, you should not create arbitrary attributes on tags. You can, but it is invalid for the schema.
With HTML5, the best practice is to use
data-attributes.eg.