<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'call a table with a input button command? And use array in a table?' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'call a table with a input button command? And use array in a table?' posted on the 'JavaScript' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2010 Programmers Heaven</copyright>
    <pubDate>Mon, 15 Mar 2010 20:44:43 -0700</pubDate>
    <lastBuildDate>Mon, 15 Mar 2010 20:44:43 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>call a table with a input button command? And use array in a table?</title>
      <link>http://www.programmersheaven.com/mb/java-script/216597/216597/call-a-table-with-a-input-button-command-and-use-array-in-a-table/</link>
      <description>Right now Iam working on a Students Data table. I made a button in my script but Iam not sure how you would make it so on click it would display my table? &amp;lt;input type= "button" Name="Grades Of all Students" onclick=   &lt;br /&gt;
My other question is there away so that can I use StudentsData[0]from my array and put it in my table instead of typing &amp;lt;TD&amp;gt; 120&amp;lt;/TD&amp;gt;. like document writIn (StudentsData[0]);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is my example code so Far&lt;br /&gt;
&amp;lt;HTML&amp;gt;&lt;br /&gt;
&amp;lt;HEAD&amp;gt;&lt;br /&gt;
&amp;lt;SCRIPT LANGUAGE="JavaScript"&amp;gt;&lt;br /&gt;
StudentsData = new Array (28);&lt;br /&gt;
StudentsData[0] = 120;&lt;br /&gt;
StudentsData[1] = 145;&lt;br /&gt;
StudentsData[2] = 234;&lt;br /&gt;
StudentsData[3] = 250;&lt;br /&gt;
StudentsData[4] = 278;&lt;br /&gt;
StudentsData[5] = 279;&lt;br /&gt;
StudentsData[6] = 300;&lt;br /&gt;
StudentsData[7] = "John Miller";&lt;br /&gt;
StudentsData[8] = "Cathy Johnson";&lt;br /&gt;
StudentsData[9] = "Bill Newton"&lt;br /&gt;
StudentsData[10] = "Jenny Bolton";&lt;br /&gt;
StudentsData[11] = "Bill Manson";&lt;br /&gt;
StudentsData[12] = "Kim Anderson";&lt;br /&gt;
StudentsData[13] = "Bob Newman";&lt;br /&gt;
StudentsData[14] = 84;&lt;br /&gt;
StudentsData[15] = 92;&lt;br /&gt;
StudentsData[16] = 63;&lt;br /&gt;
StudentsData[17] = 74;&lt;br /&gt;
StudentsData[18] = 99;&lt;br /&gt;
StudentsData[19] = 91;&lt;br /&gt;
StudentsData[20] = 77;&lt;br /&gt;
StudentsData[21] = "B";&lt;br /&gt;
StudentsData[22] = "A";&lt;br /&gt;
StudentsData[23] = "D";&lt;br /&gt;
StudentsData[24] = "C";&lt;br /&gt;
StudentsData[25] = "A";&lt;br /&gt;
StudentsData[26] = "A";&lt;br /&gt;
StudentsData[27] = "C"; &lt;br /&gt;
&amp;lt;input type= "button" Name="Grades Of all Students" onclick=&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/Head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;TABLE BORDER="1"&amp;gt;&lt;br /&gt;
 &amp;lt;caption align="Top"&amp;gt;This is the Students Data&amp;lt;/caption&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TH&amp;gt;Student Number   &amp;lt;TH&amp;gt; Name  &amp;lt;TH&amp;gt; Score    &amp;lt;TH&amp;gt; Grade &amp;lt;/TH&amp;gt; &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 120&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; John Miller&amp;lt;/TD&amp;gt;  &amp;lt;TD&amp;gt;84 &amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; B &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 145&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Cathy Johnson&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; 92&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; A &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 234&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; Bill Newton&amp;lt;/TD&amp;gt;  &amp;lt;TD&amp;gt;63 &amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; D &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 250&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Jenny Bolton&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; 74&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; C &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 278&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Bill Manson&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; 99&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; A &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 279&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; Kim Anderson&amp;lt;/TD&amp;gt;  &amp;lt;TD&amp;gt;91 &amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; A &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
 &amp;lt;TR&amp;gt; &amp;lt;TD&amp;gt; 300&amp;lt;/TD&amp;gt;&amp;lt;TD&amp;gt;Bob Newman&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; 77&amp;lt;/TD&amp;gt; &amp;lt;TD&amp;gt; C &amp;lt;/TD&amp;gt;  &amp;lt;/TR&amp;gt;&lt;br /&gt;
&amp;lt;/TABLE&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/216597/216597/call-a-table-with-a-input-button-command-and-use-array-in-a-table/</guid>
      <pubDate>Tue, 07 Oct 2003 09:19:22 -0700</pubDate>
      <category>JavaScript</category>
    </item>
    <item>
      <title>Re: call a table with a input button command? And use array in a table</title>
      <link>http://www.programmersheaven.com/mb/java-script/216597/220148/re-call-a-table-with-a-input-button-command-and-use-array-in-a-table/#220148</link>
      <description>When I have "lots" of data like this, I usually create a class that defines the particular records...&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
function StudentData(num, name, score, grade) {
   this.StudentNumber = num;
   this.Name = name;
   this.Score = score;
   this.Grade = grade;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Then I will create an array of those records&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
var Records = new Array();   //Master record

//Function that add a student record to the array
function AddStudent(pNum, pName, pScore, pGrade) {
   Records[Records.length] = new StudentData(pNum, pName, pScore, pGrade);
}

//Add your students here
AddStudent(123, "Student Name", 100, "A");
AddStudent(124, "Student Name", 100, "A");
...
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Then for the writing part, what i will do is shove everything in a DIV and then set the style:display = none...&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;

var sHTML = '&amp;lt;div id="studentTable" style="display:none;"&amp;gt;';
sHTML += '&amp;lt;table border="0" .... &amp;gt;';

//Iterate through the array to display the rows
for (var i=0; i&amp;lt;Records.length; i++) {
   sHTML += '&amp;lt;tr&amp;gt;';
   sHTML += '&amp;lt;td&amp;gt;' + Records[i].StudentNumber + '&amp;lt;/td&amp;gt;';
   sHTML += '&amp;lt;td&amp;gt;' + Records[i].Name + '&amp;lt;/td&amp;gt;';
   ....
   sHTML += '&amp;lt;/tr&amp;gt;';
}

sHTML += '&amp;lt;/table&amp;gt;&amp;lt;/div&amp;gt;';
document.write(sHTML);
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Then for your button, use onclick="showTable()", which will basically change the display style of the DIV to "" (nothing, or showing it)&lt;br /&gt;
and here is showTable():&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
function showTable() {
   //This is where do will need to do some browser check.. which i don't remember very clearly
   //Here, studentTable is the id of the DIV we created earlier
   if (document.all) {
       document.all['studentTable'].style.display = "";
   }
   else if (document.getElementById) {
       document.getElementById('studentTable').style.disp
lay = "";
   }
   else {
       //not very sure about this one, it's for older browsers
       document.layers['studentTable']......
   }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I didn't test the script so i can't say 100% that it will work...&lt;br /&gt;
&lt;br /&gt;
Good luck&lt;br /&gt;
Phazxero&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java-script/216597/220148/re-call-a-table-with-a-input-button-command-and-use-array-in-a-table/#220148</guid>
      <pubDate>Sat, 25 Oct 2003 15:39:42 -0700</pubDate>
      <category>JavaScript</category>
    </item>
  </channel>
</rss>