Joe Park
Joe Park

Reputation: 139

How to get variable data out of the html table

from the part of table I have,

else if (c == 1)
        {
            var startTime = "h:mm AM/PM";
            $("<td>")
                .addClass("tableCell")
                .html("<input type='text' value='" + startTime + "' />")
                .data("col", c)
                .appendTo(trow);

            //col[counter] = startTime;
            //counter++;
            //masterCounter++;
        }

out of this, I just want the output of startTime out. However, if I use these codes,

var content = document.getElementsByTagName('td');

col[counter] = content[c].innerHTML;
            alert ('td cell number '+(counter)+' contains: ' +col[counter]);

I will get input type='text' value='" + startTime + "' / as output for col[counter]

is there anyway so I only get value startTime out of it?

Upvotes: 1

Views: 322

Answers (2)

Joe Park
Joe Park

Reputation: 139

I found the answer! You were correct ShankarSangoli.

I just had to enter

col[counter] = $('td').eq(c).find('input').val();

instead of

content = $('td')

Thank you!

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69905

Use this.

var content = $('td');

col[counter] = content.eq(c).find('input').val();
alert ('td cell number '+(counter)+' contains: ' + col[counter]);

Upvotes: 1

Related Questions