Solved

simple table and default value should come via my array content

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html value of radio 14 31
ajax to record click 3 16
CSS DIV Height in Percent 1 9
Clear input text 15 8
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

820 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