Solved

simple table and default value should come via my array content

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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)

746 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

11 Experts available now in Live!

Get 1:1 Help Now