1

I am having a little problem here. I have a <script language ="JavaScript" runat="server"> code that reads a table from a website, parses data and stores it in a 2-D array. It works correctly; I can display the data using Response.Write.

Now, I would like to use the data in the array to construct my own table and display it in the browser. I thought I would just add:

</head> 
<body onload="tableCreator();">
<table id="table" border="1">
    <tr> 
    <td id="Document Number">Document Number</td>
    <td id="Document Link">Document Link</td>
    <td id="Date Filed">Date Filed</td>
    <td id="Date Entered">Date Entered</td>
    <td id="Date Terminated">Date Terminated</td>
    <td id="Description">Description</td>
    </tr>
</table> 
<body> 
</html>

after script ends, but this is where problems start. I don't know where to insert the tableCreator()function. If I do it inside the (script language ="JavaScript" runat="server") code (in order to be able to use the array's data), the function is not called. When I change the tag to (script language ="JavaScript") (no runat="server"), the function is called, but the script isn't run (I have multiple Response.Write and nothing, but the table, is being printed)

function tableCreator () {
  var table = document.getElementById("table");
  var rowCount = table.rows.length;
  var row;
  row = table.insertRow(rowCount);
  var cell1 = row.insertCell(0);
  cell1.innerHTML = "1";
}

Any ideas?

2
  • 1
    Are you using ASP.NET? Sounds like you're mixing server-side code with client-side Commented May 23, 2012 at 19:28
  • Looks like it. I am a newbie :( What approach should I use to accomplish what I want, i.e. parse a table from a website, store the data and create a table using the data? Commented May 23, 2012 at 19:30

1 Answer 1

1

You are confusing server-side code and client-side code.

JavaScript can't access a 2d array that's created on the server (adding runat="server" to you script tag will not give you access to your server-side variables). You would need to serialize the array in your server-side language and then make it accessible to the client (a hidden field would work well for this).

Alternatively, if you have the data server-side, why create the table client-side. Simply create the table server-side when the page loads.

Sign up to request clarification or add additional context in comments.

6 Comments

The thing is, there is no need for server-client communication. This is only designed to do a simple task of parsing, collecting, and displaying in a new table the data from the given website's table.
@Krzysiek, where is the 2d array being created? On the server or on the client?
How would I create such a table? I'm confused. Sorry... server
What's your server-side language? C# or VB?
@Krzysiek, JavaScript is a client side language. It seems that you're new to this programming stuff. If that's the case, you should be avoiding 2d arrays altogether. Where is the 2d array being created? Can you post the code that creates it?
|

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.