I am working on a project with asp.net and vb.net language system.
Now I made a table on the asp file, and before clicking on a button "update", by JavaScript, I would like to get all the string data written in the text boxes each placed inside a cell of the table.

Now, I wrote the following codes;

function getData(){
        var tblData = new Array();          
        var table = document.getElementById("<%=tblA.ClientID%>");
        var i;
        var txt;
        var txt2;

        tr = table.getElementsByTagName('tr');
        for (i = 0; i < tr.length; i++) {
            var ttl = "txt : ";
            var ttl2 = "txt2 : ";

            td = tr[i].getElementsByTagName('td');
            txt = td[4].childNodes[0].nodeValue; //This is wrong...
            txt2 = td[10].childNodes[0].nodeValue; //This is wrong...
            alert(ttl + txt + ttl2 + txt2);

            tblData[i, 1] = txt;
            tblData[i, 2] = txt2;
       // Here, I would like to send the array object containing the data of the textboxes. How can I do it?
        return true;

Now, please let me know what to wrote to get the texts from the textboxes, and how to send the array data to the server for update_click function to get it.

Edited by mike_2000_17: Fixed formatting

7 Years
Discussion Span
Last Post by essential

Shouldn't this be in the ASP forum? If you want help with JS just post some of the pure HTML, not ASP/VB


Im not sure if this is exactly what you need.
But this will help you to get your things done.

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="#internal"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
<html id="xhtml10" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>JavaScript Demo</title>
<style id="internal" type="text/css" charset="ISO-8859-1">
/* <![CDATA[ */
body { min-height: 600px; }
form {
   background: #ddd;
   border: 2px solid #ccc;
   margin: 40% auto 0 auto;
   padding: .7em;
   vertical-align: middle;
   width: 80%; }

td[id] { 
   padding: .5em 1.5em .3em .5em;
   line-height: 120%;
   width: auto;
   text-align: left;
   vertical-align: top; }

th {
   padding-right: 1em;
   padding-top: .5em;
   text-align: left;
   vertical-align: top; }

input[type="submit"] { 
   margin-top: .5em; }

/* ]]> */ 
<script type="text/javascript">
/* <![CDATA[ */
var count = 1;
function updateCell(form) {
var arrays = [];
var inputTxt = [];
var cell = document.getElementById('data').getElementsByTagName('td');
document.getElementById('field1').innerHTML = '';
if ( form ) {
   with( form ) {
   inputTxt[0] = txt0.value;
   inputTxt[1] = txt1.value;
for ( var i = 0; i < inputTxt.length; i++ ) {
   arrays[i] = inputTxt[i]; 
} for ( var x = 0, m = arrays[0].split(' '); x < m.length; x++ ) {

/* Converting input values into an array, separating each value with white spaces */

cell['field0'].innerHTML += '<strong>' + (count++) + '.</strong> ' + m[x] + '<br />';
      } for ( var y = 0, n = arrays[1].split(' '); y < n.length; y++) {

/* Another way to store text--
   Skipping the work by listing all the input value using the list element. */
   document.getElementById('field1').innerHTML += '<li>' + n[y] + '</li>'; 
  } return false;
/* ]]> */
<form action="#" onsubmit="return updateCell(this);">
<table id="data" summary="A JavaScript Demo">
<th><label for="txt0">Field 1</label></th>
<td colspan="3"><input type="text" size="40" id="txt0" name="txt0" value="" />
<th><label for="txt1">Field 2</label></th>
<td colspan="3"><input type="text" size="40" id="txt1" name="txt1" value="" />
<th style="vertical-align: text-top; padding-top: .5em;" rowspan="2">Output:</th>
<th>Text 1:</th>
<td id="field0"></td>
<td style="text-align: right;"><input type="submit" id="btn" name="btn" value="update" /></td>
<th>Text 2:</th>
<td colspan="1" id="demo"><ol id="field1" style="margin: 0 0 0 1.2em;"><li>Update</li></ol></td>

This demo will convert all text value into an array separated by white spaces.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.