Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 28th, 2005, 06:19 AM
Registered User
 
Join Date: Oct 2005
Location: somajiguda, andhra pradesh, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamically loading table using javascript

hi , to one and all
i want to dynamically create tables with input boxes and drop down boxes depending on the option that is selected in a drop down box .
this is the code upto which i was able to do
go through this and help me implementing the feature i want.
code


<head>
<title>Sample code - Traversing an HTML Table with JavaScript and DOM Interfaces</title>
<script>
    function start() {
        var index;
        var x=document.getElementById("department");
        index =x.selectedIndex ;
        if(index ==1)
        {
        // get the reference for the body
        var mybody=document.getElementsByTagName("body").item( 0);
        // creates an element whose tag name is TABLE
        mytable = document.createElement("TABLE");
        // creates an element whose tag name is TBODY
        mytablebody = document.createElement("TBODY");
        // creating all cells
        for(j=0;j<2;j++) {
            // creates an element whose tag name is TR
            mycurrent_row=document.createElement("TR");
            for(i=0;i<2;i++) {
                // creates an element whose tag name is TD
                mycurrent_cell=document.createElement("TD");
                // creates a Text Node
                currenttext=document.createTextNode("cell is row "+j+", column "+i);
                // appends the Text Node we created into the cell TD
                mycurrent_cell.appendChild(currenttext);
                // appends the cell TD into the row TR
                mycurrent_row.appendChild(mycurrent_cell);
            }
            // appends the row TR into TBODY
            mytablebody.appendChild(mycurrent_row);
        }
        // appends TBODY into TABLE
        mytable.appendChild(mytablebody);
        // appends TABLE into BODY
        mybody.appendChild(mytable);
        // sets the border attribute of mytable to 2;
        mytable.setAttribute("border","2");
        mytable.setAttribute("align","left");
        }
        else
        if (index ==2)
        {
             // get the reference for the body
        var mybody=document.getElementsByTagName("body").item( 0);
        // creates an element whose tag name is TABLE
        mytable = document.createElement("TABLE");
        // creates an element whose tag name is TBODY
        mytablebody = document.createElement("TBODY");
        // creating all cells
        for(j=0;j<2;j++) {
            // creates an element whose tag name is TR
            mycurrent_row=document.createElement("TR");
            for(i=0;i<3;i++) {
                // creates an element whose tag name is TD
                mycurrent_cell=document.createElement("TD");
                // creates a Text Node
                currenttext=document.createTextNode("cell is row "+j+", column "+i);
                // appends the Text Node we created into the cell TD
                mycurrent_cell.appendChild(currenttext);
                // appends the cell TD into the row TR
                mycurrent_row.appendChild(mycurrent_cell);
            }
            // appends the row TR into TBODY
            mytablebody.appendChild(mycurrent_row);
        }
        // appends TBODY into TABLE
        mytable.appendChild(mytablebody);
        // appends TABLE into BODY
        mybody.appendChild(mytable);
        // sets the border attribute of mytable to 2;
        mytable.setAttribute("border","2");
        mytable.setAttribute("align","left");
        }
        //mytable.setAttribute("disabled","false");

    }
</script>
</head>
<body >
<select size="1" id="department" onchange="start()">
<option value selected="0"></option>
<option value="1">biotech</option>
<option value="2">PHARMA <OPTION>
<input type="text" name="kalyan" value="kalyan">
</body>
</html>



kalyan
Reply With Quote
  #2 (permalink)  
Old November 1st, 2005, 07:21 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

i am not sure what your question is? is this a tip? if so, put Tip: before your post title. cheers.

www.crmpicco.co.uk
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
loading an image dynamically into my report orson4music Crystal Reports 1 January 4th, 2008 09:35 AM
Loading forms dynamically bmains C# 2005 1 November 30th, 2005 03:53 PM
Dynamically Class Loading form jar saiyedriyaz J2EE 1 February 28th, 2005 05:41 AM
Loading user control dynamically from code-behind jacob ASP.NET 1.0 and 1.1 Basics 2 April 12th, 2004 06:06 PM



All times are GMT -4. The time now is 05:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.