Solved

simple table and default value should come via my array content

Posted on 2014-02-25
2
324 Views
Last Modified: 2014-02-25
Hi;

I have a simple table and in it there are textboxes. I want default values in my array to be appearing in my textboxes by default. Any simple example?

Regards.
0
Comment
Question by:jazzIIIlove
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
cstsang earned 500 total points
ID: 39885044
Is it what you need?
<html>
  <head>
    <script language=javascript>
      var myCars=new Array("Saab","Volvo","BMW");
      function loadData()
      {
        var t=document.getElementById("t1");
        for (var i in myCars)
          {
              // Insert a row in the table at the last row
              var newRow   = t.insertRow(t.rows.length);
              // Insert a cell in the row at index 0
              var newCell  = newRow.insertCell(0);
              var textBox=document.createElement("input");
              textBox.type="text";
              textBox.value=myCars[i];
              newCell.appendChild(textBox);
          }
      }
    </script>
  </head>
  <body onload="loadData()">
      <table id="t1" border=1>
      </table>
  </body>
</html> 

Open in new window

0
 
LVL 7

Expert Comment

by:cstsang
ID: 39885061
Another example:
<html>
  <head>
    <script language=javascript>
      var myCars=new Array("Saab","Volvo","BMW");
      function loadData()
      {
        var t=document.getElementById("t1");
        for (i=0;i<t.rows.length;i++)
        {
          row=t.rows[i];
          for (j=0;j<row.cells.length;j++)
          {
            cell=row.cells[j];
            textBox=cell.getElementsByTagName('input')[0];
            textBox.value=myCars[i];
          }
        }
      }
    </script>
  </head>
  <body onload="loadData()">
      <table id="t1" border=1>
        <tr>
          <td>
              <input type="text">
          </td>
        </tr>
        <tr>
          <td>
              <input type="text">
          </td>
        </tr>
        <tr>
          <td>
              <input type="text">
          </td>
        </tr>
      </table>
  </body>
</html>    

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now