2

I am trying to populate an HTML table from data that is in a two-dimensional array. The data is coming to an $.ajax script from a php/MySQL query. I'm successfully parsing the data in the success function and I can read out the array element contents to the console, but I can't figure out why the values won't populate the HTML table.

See this jsFiddle for my work.

In the console I can populate the input in any of the table cells with this jQuery notation:

$('#tblApTdms tr:nth-child(4) td:nth-child(3) input').val('q34rfewa')

but it won't populate in the jsFiddle, in the Web application I'm building, nor in an isolated test page.

I must be missing something here!

2 Answers 2

3

Try putting parenthesis around the addition equations:

$('#tblApTdms tr:nth-child(' + (r + 1) + ') td:nth-child(' + (c + 1) + ') input').val(note);
Sign up to request clarification or add additional context in comments.

5 Comments

That works (I'll mark it as the answer when it'll let me), but when I copy/pasted that working code from jsFiddle to my bare-bones, isolated test page, the cells aren't populating. Any ideas?
I'm sorry, I am not sure. Is your test page similar to the jsfiddle?
The test page has just the jQuery reference, the html and the javascript. Weird - and frustrating!
Have you looked at the console to see if there are any errors?
I got it: I copy/pasted the code to an area outside of the jQuery function. Whew!
1

You need to use parens:

    $('#tblApTdms tr:nth-child(' + (r + 1) + ') td:nth-child(' + (c + 1) + ') input').val(note);

Without the parens, it thinks you're trying to append strings, since that is the prior context.

Comments

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.