Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2002
    Location
    opposite lock
    Posts
    934

    javascript: dynamic web page, table

    basically what i want to do is dynamically build a table.

    I would like to come to a website that said

    ____ _____ _____ (3 blanks)

    and a button to say "add some more" where clicking on the link would cause another 3 blanks to appear in the next row. i basically just need to understand how to dynamically build a table in javascript.

    links or explanations, either are great
    jubba joo!

  2. #2
    Join Date
    Mar 2004
    Location
    Cleveland, Ohio
    Posts
    182
    Hello,

    You might want to try searching http://www.javascriptsource.com

    They have a lot of javascript codes, the only problem is their search engine isn't to good and takes a little time to find what your looking for.
    SepCity.com - Content Management / Portal Software Solutions
    Host on our network or buy our software to host on your own server

  3. #3
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    This should do it :

    Code:
    <script type="text/javascript">
    var counter = 0;
    
    function moreFields()
    {
    	counter++;
    	var newFields = document.getElementById('source).cloneNode(true);
    	newFields.id = '';
    	newFields.style.display = 'block';
    	var newField = newFields.childNodes;
    	for (var i=0;i<newField.length;i++)
    	{
    		var theName = newField[i].name
    		if (theName)
    			newField[i].name = theName + counter;
    	}
    	var insertHere = document.getElementById('destination');
    	insertHere.parentNode.insertBefore(newFields,insertHere);
    }
    
    window.onload = moreFields;
    </script>
    <a href="#" onclick="moreFields();">add blanks</a>
    <div id="source">
    <tr><td><input type="text"></td></tr>
    <tr><td><input type="text"></td></tr>
    <tr><td><input type="text"></td></tr>
    </div>
    <div id="destination"></div>
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    Join Date
    Dec 2002
    Location
    opposite lock
    Posts
    934
    It seems like no matter what i do i get an error that says "object expected."
    jubba joo!

  5. #5
    Join Date
    Dec 2002
    Location
    opposite lock
    Posts
    934
    OH! there was an apostrophe missing here:

    getElementById('source).

    should be:
    getElementById('source').

    Thanks though, this code does just what i want!
    jubba joo!

Posting Permissions

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