Reputation: 987
I'm creating a clickable calendar, where each cell can be marked 'green' or 'red'. This should be recorded in the DB. I thought of dynamically assigning each <td>
an informative id, e.g.
<td id="1-2013-16-1" class="green">16</td>
Then get the id with jQuery and send it to php using ajax, for every cell that has been clicked.
This is possible and working, but something tells me id's are not meant for this. Is this a reasonable way to identify the info needs to be sent for each cell? Or, what is a better way of doing this?
Upvotes: 2
Views: 121
Reputation: 4022
I think it is appropriate to use the id field here, since it IS actually an id ;) It is fine to submit it to PHP then to update something in the database. You could use any other custom attribute, but I think id is very well suited here.
Upvotes: 0
Reputation: 17171
That's an okay way, but make sure you're checking the id's you receive in PHP because somebody could send anything they would like to your server under the guise of the id.
Upvotes: -1
Reputation: 28147
Use HTML5 custom data attribute:
<td data-date="1-2013-16-1" class="green">16</td>
To get the value with jQuery:
$('td').attr('data-date');
You can set any number of data-*
attributes.
Upvotes: 7