Results 1 to 2 of 2

Thread: Create table based on value from select box

  1. #1
    Join Date
    Mar 2012

    Create table based on value from select box

    I'm new to javascript and I'm trying to create a table based on the number selected from a dropdown. The code I have so far are from samples I found and tried to piece together, but obviously don't work

    Here is the code I have so far:
    <script language="Javascript" type="text/javascript">
    function People () {
      var PeopleNbr = people;
      for(i = 0; i < PeopleNbr; i++){
        document.write('<tr><td>row ' + i + ')
        for (j = 0; j < CourseFee; j++){
          document.write('column ' + j + '</td>')
    <form name="selectForm">
    <p>How many people to you want to add:</p>
    <select id="people" onchange="People(this.value)">
    <option value="0">Select Number</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    So lets say I select 2 from the select dropdown I need it to display the following:

    First Name: Person #1 Person #2

    but in a table format.

    If someone has the time to help me I would greatly appreciate it

    Thank you in advance

  2. #2
    Join Date
    Mar 2011
    You can't use document.write() to dynamically create elements within a page. You need to use createElement() and appendChild(), which are DOM functions. It is unlikely that you'll be able to use those functions without a more extensive knowledge of JavaScript.

    Do yourself a favor and take the time to learn how JavaScript works. You'll waste more time through trial and error trying to cut and paste other people's code into your pages until you gain more experience than it will take for you to learn what you need to know. There are several online tutorials that will teach you the basics. Once you have the fundamentals down, you'll be able to see why things work and why they don't. Good luck!
    Rick Trethewey
    Rainbo Design

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center