2

I have some Javascript that I am using to allow for dynamically added rows on a page. How can I pass this query and dropdown to the dynamically created table cell?

Javascript for dynamically adding cells:

<script language="javascript">
//add a new row to the table
var rownumber = 0;

function addRow()
{
    rownumber++;
    //add a row to the rows collection and get a reference to the newly added row
    var newRow = document.all("tblGrid").insertRow();

    //add 3 cells (<td>) to the new row and set the innerHTML to contain text boxes

    var oCell = newRow.insertCell();
    oCell.innerHTML = "<input type='text' name='t1' id=rownumber>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "<input type='text' name='t2' id=rownumber>Test Client Input Row<input" + 
                      " type='button' value='Delete' onclick='removeRow(this);'/>";   
}

//deletes the specified row from the table
function removeRow(src)
{
    /* src refers to the input button that was clicked. 
       to get a reference to the containing <tr> element,
       get the parent of the parent (in this case <tr>)
    */   
    var oRow = src.parentElement.parentElement;  

    //once the row reference is obtained, delete it passing in its rowIndex   
    document.all("tblGrid").deleteRow(oRow.rowIndex);  

}
</script>

Query and dropdown list code:

<TR>
<TD><select name = "cno">
<option value=""></option>
<%
strSQL1 = "select cno, aliasname from Clients order by Aliasname asc"
Set rs1 = objConnection.Execute(strSQL1, ,adCmdText)
call ErrorHandler(err)
arr1 = rs1.GetRows()

for i = 0 to UBound(arr1,2)

    cno = trim(arr1(0,i))
    aliasname = trim(arr1(1,i))

%>
<option value = "<%=cno%>"><%=aliasname%></option>
<%
next

%>
</select></td></TR>
<TR>
J.J.
  • 1,128
  • 2
  • 23
  • 62
  • You're trying to copy the dropdown from another row in the table? – Nathan Rice Mar 11 '15 at 17:42
  • Basically I want to insert the same dropdown into ocell, but was unsure of how to do so within the javascript. – J.J. Mar 11 '15 at 17:45
  • Basically you can't. Since ASP is a server side language, that dropdown is getting rendered server side before it's sent to the client. So there is no way to reconstruct it other than copying it from an existing element on the page, or creating a service server side that will return some JSON or XML and you then recreate it from the data returned by your service. – Nathan Rice Mar 11 '15 at 17:47
  • In that case, is there a way I could copy over the currently selected dropdown value to the created cell? – J.J. Mar 11 '15 at 18:42
  • 1
    http://stackoverflow.com/questions/3301688/how-do-you-get-the-currently-selected-option-in-a-select-via-javascript – Nathan Rice Mar 11 '15 at 22:13
  • 1
    You could try [this](http://stackoverflow.com/questions/28419398/reload-html-table-data-after-database-entry-deleted/28430525#28430525); basically ajax without the bells and whistles. – Paul Mar 12 '15 at 09:15

0 Answers0