www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: problem

  1. #1
    Join Date
    Apr 2006
    Posts
    52

    problem

    hi
    I am using the code below to allow the user to click a button and when pushed a new row appears in a table with a <SELECT> drop down box appearing.

    Problem is that I think I am not coding it correctly, as it shows drop down twice.

    Can someone help?

    thanks
    Craig.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script language="javascript"> 
    var Table2RowId = 0; 
    
    function addRow_table2() 
    { 
    Table2RowId++; 
    var tbody = document.getElementById('table2').getElementsByTagName('tbody')[0]; 
    
    var row = document.createElement('TR'); 
    
    var cell1 = document.createElement('TD');
    
    var inp1 =  document.createElement('SELECT'); 
    inp1.setAttribute('name','selectvar'+Table2RowId);
    
    //cell1.innerHTML = "<select name='service" + Table2RowId + "'><option value='1'>Microsoft</option><option value='2'>Macromedia</option>";
    cell1.innerHTML= myDiv.innerHTML
    
    row.appendChild(cell1); 
    tbody.appendChild(row); 
    } 
    </script> 
    <div id="myDiv">
      <select name="firstSelect" >
        <option>11111</option>
        <option>22222</option>
        <option>33333</option>
      </select>
    </div>
    </head>
    <body>
    
      <table width="50%" border="1" id="table2">
        <tr> 
          <td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Software 
            Manufacturer</font></td>
        </tr>
      </table>
      <input type="button" value="Insert Row" name="b2" onClick="addRow_table2();">
    
    </body>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Somehow confusing... Which are your main aims, after all? Can you detail a little bit your project specifications?

  3. #3
    Join Date
    Apr 2006
    Posts
    52
    Hi,
    Basically, I want a dynamic drop down box to appear in each row when a button is clicked.. the user then selects an option for each row than clicks Submit.

    hopw this helps.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function addRow(tabid){
    var mydata=
    {
    '1':'Microsoft',
    '2':'Micromedia',
    '3':'Apple'
    }
    var root=document.getElementById(tabid).getElementsByTagName('tbody')[0]
    var n=root.getElementsByTagName('tr').length;
    var row=document.createElement('tr');
    var cell=document.createElement('td');
    var sel=document.createElement('select');
    sel.name='service'+n;
    var opt;
    for(a in mydata){
    opt=document.createElement('option');
    opt.value=a;
    opt.appendChild(document.createTextNode(mydata[a]));
    sel.appendChild(opt)
    }
    cell.appendChild(sel);
    row.appendChild(cell);
    root.appendChild(row)
    }
    </script>
    </head>
    <body>
    <form>
    <table width="50%" border="1" id="table2">
        <tr> 
          <td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Software 
            Manufacturer</font></td>
        </tr>
      </table>
      <input type="button" value="Insert Row" name="b2" onclick="addRow('table2');">
      </form>
    </body>
    </html>

  5. #5
    Join Date
    Apr 2006
    Posts
    52
    Quote Originally Posted by Kor
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function addRow(tabid){
    var mydata=
    {
    '1':'Microsoft',
    '2':'Micromedia',
    '3':'Apple'
    }
    var root=document.getElementById(tabid).getElementsByTagName('tbody')[0]
    var n=root.getElementsByTagName('tr').length;
    var row=document.createElement('tr');
    var cell=document.createElement('td');
    var sel=document.createElement('select');
    sel.name='service'+n;
    var opt;
    for(a in mydata){
    opt=document.createElement('option');
    opt.value=a;
    opt.appendChild(document.createTextNode(mydata[a]));
    sel.appendChild(opt)
    }
    cell.appendChild(sel);
    row.appendChild(cell);
    root.appendChild(row)
    }
    </script>
    </head>
    <body>
    <form>
    <table width="50%" border="1" id="table2">
        <tr> 
          <td><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Software 
            Manufacturer</font></td>
        </tr>
      </table>
      <input type="button" value="Insert Row" name="b2" onclick="addRow('table2');">
      </form>
    </body>
    </html>
    Hi,thanks but I have aleady done it this way.. the problem is that I need to fill the select box dynamicly from an ADO record set (using ASP)

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    then write the property/values pairs of the mydata object using ASP

  7. #7
    Join Date
    Apr 2006
    Posts
    52
    Quote Originally Posted by Kor
    then write the property/values pairs of the mydata object using ASP

    Hi, client side javascript cannot access server side variables.. thats the problem.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by cjonline
    Hi, client side javascript cannot access server side variables.. thats the problem.
    Yeap, but server side language can write javascript variables on a page, that is what i mean.

  9. #9
    Join Date
    Apr 2006
    Posts
    52
    Hi, I dont know how to do that.. can you post an example?

  10. #10
    Join Date
    Apr 2006
    Posts
    52
    anybody help me with this please?

  11. #11
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I'll make a copy of the thread to the ASP forum

  12. #12
    Join Date
    Apr 2006
    Posts
    52
    Hi,
    Can anyone help me with this?

    I require asp to write javascript variables on a page (see previous posts)

  13. #13
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  14. #14
    Join Date
    Apr 2006
    Posts
    52
    Kor,
    I dont think you've read my problem correctly.. I know how to retrieve data from a databse and display it to the screen.. the problem is that when a users clicks the add row button it creates a new ROW in my table with a drop down box (this works, using javascript). I need the drop down to contain dynamic information from an asp recordset.. thats the problem.. I dont know how to pull the recordset from the drop down box (created in javascript)

    thanks.

  15. #15
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I don't know ASP (but as I know PHP, I guess there must be no basic differences). Presuming you have created an ASP object from DB which has properties, and properties have values, you may build a javascript array.
    Code:
    var myArr=[
    '<% Response.Write objRS("objProperty1") %>',
    '<% Response.Write objRS("objProperty2") %>',
    '<% Response.Write objRS("objProperty3") %>'
    ]
    Now you can use that array's elements in your javascript code (myArr[0], myArr[1], myArr[2]).
    Last edited by Kor; 10-09-2007 at 06:04 AM.

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



Recent Articles