2

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.

2 Answers 2

3

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks..Its awesome...You save my day.
3

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.

1 Comment

I think that deserves +1 just for working out what on earth the OP wanted. It was certainly unclear to me. So why was the string being treated as an arithmetic expression? Or was that pure coincidence?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.