Solved

Dropdown menu help in add row script

Posted on 2004-03-26
3
223 Views
Last Modified: 2008-03-10
I using the code below and the dropdown menu works fine for the database populated dropdown list.  What I want if when I click Add it creates the database populated list again.  If I move the asp script into the line item(0).childNodes[1].innerHTML = "<SELECT SIZE=1 NAME=phone" + ind + "></SELECT>" and remove all the " for ' nothing happens.  Can someone help?

<%
Dim cnOsmitDatabase
%>
<html>
<head>
<script language="javascript">
function addRow(tbl){
 var tb = tbl.firstChild;
 var ind = tb.childNodes.length;
 var nr = document.getElementById('cloneThis').cloneNode(true);
 nr.style.display = "block";
 with(nr.firstChild.firstChild.firstChild.childNodes){
   item(0).childNodes[1].innerHTML = "<SELECT SIZE=1 NAME=phone" + ind + "></SELECT>"
 }
 tb.appendChild(nr);
 if (tbl.rows.length > 1) {
   document.getElementById('delRow').disabled = false;
 }
 document.forms[0].count.value = ind + 1;
}

function deletRow(tbl){
  if (tbl.rows.length > 1) {
    tblRow = tbl.deleteRow(tbl.rows.length-1);
    //           alert(tbl.rows.length);
  }
}
function disablit(tbl){
  if(tbl.rows.length == 1) {
    document.getElementById('delRow').disabled = true;
  }
}
</script>
<!-- #INCLUDE FILE="dbconnection/connect.asp" -->
</head>
<body>
<%
  count = request.form("count")
  for i = 0 to cint(count) - 1
    phone = request.form("phone" & i)
    response.write "phone = " & phone & "<br>"
  next
%>
<form name="addAccount" method="post" >
<%
      DBConnect

      Dim rsHWProdCat
      Dim rsSWProdCat
             
      Dim strSQL
                   
      Set rsSWProdCat1 = Server.CreateObject("ADODB.RecordSet")

      ' SQL to get the software titles.
      strSQL = "SELECT * FROM software WHERE (([StdBuildComponent] = FALSE) AND ([Status] = 'Approved')) ORDER BY [Software Title] ASC;"
      rsSWProdCat1.Open strSQL, cnOsmitDatabase
 %>
<input type=hidden name="count" value="1">
<table id="purchase">
<tr id='cloneThis'>
<td>
<table border=0>
<tr>
<td>Phone</td>
<td colspan=5><SELECT SIZE="1" NAME="phone0">
<%
          if Not rsSWProdCat1.EOF Then
      rsSWProdCat1.MoveFirst
      Do While Not rsSWProdCat1.EOF
      Response.Write "<option value=" & chr(34) & rsSWProdCat1.Fields("Software Title") & " " & rsSWProdCat1.Fields("Version") & CHR(34) & ">" & rsSWProdCat1.Fields("Software Title") & " " & rsSWProdCat1.Fields("Version") & "</option>"
      rsSWProdCat1.MoveNext
      Loop
      end if
      rsSWProdCat1.Close
      Set rsSWProdCat1 = Nothing
%>
</SELECT></td>
</tr>
</table>
</td></tr>
</table>
<input type=button onclick="addRow(document.getElementById('purchase'))" value="Add">
<input type=button id="delRow" name="delRow" onclick="deletRow(document.getElementById('purchase'));disablit(addContact);" value="Delete" disabled>
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
0
Comment
Question by:gifford_c
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
lil_puffball earned 250 total points
Comment Utility
Why do you need to recreate it? If you want to change the name of the select, use this function:

function addRow(tbl){
 var tb = tbl.firstChild;
 var ind = tb.childNodes.length;
 var nr = document.getElementById('cloneThis').cloneNode(true);
 nr.style.display = "block";
 with(nr.firstChild.firstChild.firstChild.firstChild.childNodes[1].firstChild){
   id="phone"+ind;
   name="phone"+ind;
 }
 tb.appendChild(nr);
 if (tbl.rows.length > 1) {
   document.getElementById('delRow').disabled = false;
 }
 document.forms[0].count.value = ind + 1;
}
0
 

Author Comment

by:gifford_c
Comment Utility
Worked a treat.  Points to you.
0
 
LVL 12

Expert Comment

by:lil_puffball
Comment Utility
Thanks for the points. :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now