Solved

Dropdown menu help in add row script

Posted on 2004-03-26
3
225 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
ID: 10691777
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
ID: 10691841
Worked a treat.  Points to you.
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10692059
Thanks for the points. :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

810 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