Solved

simple table and default value should come via my array content

Posted on 2014-02-25
2
326 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

808 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