Getting HTML table data (td) (i.e. text or val) using table header (th) into Textarea-Collection of common programming errors

I have SQLite3 (i.e. Spatialite query) that outputs the results into HTML table. I want to get the AsText(Geometry) data to output in

Here is the table and some assumptions.

name AsText(Geometry))
Andres Street LINESTRING(7.120068 43.583917,7.120154 43.583652,7.120385 43.582716,7.12039 43.582568,7.120712 43.581511,7.120873 43.580718)

$('#wktInput').click(function(){ ??? ??? var asTextGeometryText = $("#wktResult").text(asTextGeometryText); }); 'Should Display AsText(Geometry Column here!'

This is the DOM

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    var fieldNames = aResult.fieldNames;
    var records = aResult.data;
    var numFields = fieldNames.length;
    var numRecords = records.length;
    var container = document.getElementById('queryResults');
    container.innerHTML = '';
    var table = document.createElement('table');
    container.appendChild(table);
    var headerRow = document.createElement('tr');
   table.appendChild(headerRow);
    for(var i = 0; i < numFields; i++){
        var header = document.createElement('th');
        header.innerText = fieldNames[i];
        headerRow.appendChild(header);
    }

    for(var i = 0; i < numRecords; i++){
        var tableRow =  document.createElement('tr');
        table.appendChild(tableRow);

        for(var j = 0; j < numFields; j++){
            var tableData = document.createElement('td');
            tableRow.appendChild(tableData);
            tableData.innerText = records[i][j];
        }
    }
}




Thanks in advance

It seems that texarea uses id for value.

example text [This problem is related to textarea in jQuery as well][1]

This example below demonstrate that jquery is not working in textarea using id.

    
$(function() {
    $('button').click(function() {
        var row = $('input:first').val();
        var column = $('input:eq(1)').val();
        var cell = $('table tr:eq('+row+') td:eq('+column+')');
        if (cell.length == 0) {
            $('#value').text('Undefined');
        }
        else {
            $('#value').text(cell.text());
        }
    });
});




Table Cell Value


Cell 1-1 Cell 1-2 Cell 1-3
Cell 2-1 Cell 2-2 Cell 2-3
Cell 3-1 Cell 3-2 Cell 3-3

Row: Column: Value: ?
Textarea: Try this! this is not working Get Value

All is working in this example. Then added a textarea to see if I can make it work. Textarea is not working in this example. Something wrong with jquery and textarea using id as well as name.

Textarea: Try this! this is not work as well

How this does not work.

New info about this textarea value.

$('#id_of_textarea').attr('value'); //to get and...
$('#id_of_textarea').attr('value','updated value of textarea'); //to set it...



function update_textarea(obj)
{
    $('#mydiv').text($(obj).attr('value')); //whatever you type in the textarea would be reflected in #mydiv

}

http://blog.ekini.net/2009/02/24/jquery-getting-the-latest-textvalue-inside-a-textarea/

It seems that my problem is not rendering a regular html tablet but a direct render to the screen.

The author of QuickConnect say told me,

If you want one of those values so that you can use it you need to pull it out of the 2D array.

  1. Do you mean displaying the content in AsText(Geometry) column at the textarea?

    var text = []
    $('table').find('tr:has(td)').each(function(){
        text.push($.trim($(this).find('td:eq(1)').html()));
    })
    // and you set it to your textarea
    $('textarea[name="wktResult"]').val(text.join('\n'));
    
  2. 1- assign an id attribute to your textarea to use it in jquery or if your page contain just one textarea you can use tag name insteasd.

    2- to get text of textarea you need just call text function without any parameters

    $('#wktInput').click(function(){
         var asTextGeometryText =$('table').find('th').eq(2).text();
         $('#id_of_textarea').attr('value',asTextGeometryText);
    });
    

Originally posted 2013-11-15 09:07:27.