Reputation: 43
I have a table td as follows .
$roomRowId.append("<td onclick='updateBookingRooms(" + roomId + "," + date + ")'></td>");
When user click this td i have to call javascript function
updateBookingRooms(id,date).
id becomes true value but date is not true vaue.
For example , if updateBookingRooms(1,02/04/2013) i receive id=1 and date = 0.00012419274714356681
What is the problem?How can i retrieve original date value.
Upvotes: 2
Views: 1727
Reputation: 1038790
I would recommend you to avoid using string concatenations when manipulating the DOM. Instead jQuery has a nice way to build a DOM element:
$roomRowId.append(
$('<td/>', {
text: 'some text that goes inside the td',
click: function() {
updateBookingRooms(roomId, date);
}
})
);
It's not very clear from your example whether roomId
and date
are javascript variables that you want to pass to the function or whether those are hardcoded values.
Upvotes: 3
Reputation: 34895
Use parenthesis for the arguments:
$roomRowId.append("<td onclick='updateBookingRooms(\"" + roomId + "\", \"" + date + "\")'></td>");
You can also attach the click event like this:
$('<td></td>').appendTo($roomRowId).click([roomId, date], updateBookingRooms);
Upvotes: 3