| | |
Please Help!!! Problems Adding Row Dynamically using Javascript
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 18
Reputation:
Solved Threads: 1
I have a web page where the users are supposed to be able to click a button to add a new table row. I have tried various javascripts found online but I am not a javascript person. The page is written in html and asp. I dynamically fill in the dropdown boxes from a database which change for whatever is selected from the first dropdown box. below is the code for the entire webpage. The first screenshot is when the page opens, the second screenshot is if they were to click the plus sign next to Monday. Any help on this would be greatly appreciated.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <% if request("weekending") <> "" then thisdate = cdate(request("weekending")) thisday = weekday(thisdate) fdtw=dateadd("d", -thisday, thisdate) +1 ldtw=fdtw+6 Else today=weekday(date()) fdtw=dateadd("d", -today, date()) +1 ldtw=fdtw+6 End If %> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <title>KFSA Route Sheet</title> <script language="javascript" src="modules/popupcal/popcalendarroutesheet.js"> </script> <script src="/modules/combobox/dhtmlxcommon.js"></script> <script src="/modules/combobox/dhtmlxcombo.js"></script> <script src="/modules/combobox/ext/dhtmlxcombo_whp.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="/modules/combobox/dhtmlxcombo.css"/> <script type="text/javascript"> window.dhx_globalImgPath="/modules/combobox/"; </script> <script language="javascript" type="text/javascript"> function submitexpense(thisValue) { document.routesheet.subdate.value=thisValue; document.routesheet.action='expense.asp?addedit=add'; document.routesheet.submit(); } </script> <script language="javascript" type="text/javascript"> function submitcontinue(thisValue) { document.routesheet.subdate.value=thisValue; document.routesheet.action='modules/addroute.asp'; document.routesheet.submit(); } </script> <script language="javascript" type="text/javascript"> function showCols(thisValue) { if (document.getElementById("type"+thisValue).value=="Existing") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } else if (document.getElementById("type"+thisValue).value=="Prospect") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } else if (document.getElementById("type"+thisValue).value=="Trade") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = ''; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; } else if (document.getElementById("type"+thisValue).value=="Meeting") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = ''; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; } else if (document.getElementById("type"+thisValue).value=="Office") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } else if (document.getElementById("type"+thisValue).value=="Leave") { document.getElementById("leavediv"+thisValue).style.display = ''; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; } else { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } } </script> </head> <body> <% response.write(request("adddate") & "<br>") 'response.write("First day of this week: " & fdtw & "<br>") 'response.write("Last day of this week: " & ldtw) Set oConn = Server.CreateObject("ADODB.Connection") Set oRS = Server.CreateObject("ADODB.Recordset") oConn.ConnectionString = "DSN=EbixClient;uid=********;pwd=*********" oConn.Open oRS.Open "Select Client_Code, Client_Name, Client_FName, Client_City, Client_State From dbo.Client_List WITH (NOLOCK) ORDER By Client_FName", oConn 'Now, read the Recordset into a 2d array Dim ClientListValues ClientListValues = oRS.GetRows() oRS.Close oRS.Open "Select DISTINCT ACC_DISP_NUMBER, ACC_DESCRIPTION FROM dbo.GL_ACCOUNTS WITH (NOLOCK) WHERE ((ACC_DISP_NUMBER >= 6550.00 AND ACC_DISP_NUMBER <= 6551.00) OR (ACC_DISP_NUMBER >= 6600.00 AND ACC_DISP_NUMBER <= 6601.00)) ORDER By ACC_DESCRIPTION", oConn Dim MeetingListValues MeetingListValues = oRS.GetRows() oRS.Close oConn.Close Set oRS = Nothing Set oConn = Nothing Const MyClient_Code = 0 Const MyClient_Name = 1 Const MyClient_FName = 2 Const MyClient_City = 3 Const MyClient_State = 4 Const MyMeeting_Number = 0 Const MyMeeting_Desc = 1 %> <form name="routesheet" action="" method="post"> <table width="1000" align="center" cellpadding="2" cellspacing="0"> <tr bgcolor="black"> <td border="0"> <font face="arial" size="2" color="white"><b>Travel & Expense Report - KFSA</b></font> </td> <td align="right" border="0"> <font face="arial" size="2" color="white"><b>Route Sheet for <%=Session("fname")%></b></font> </td> </tr> </table> <table align="center"> <tr> <td align=center> <font face=Arial size=2><b>Week Ending: </b></font><input id="we" style="text-align:center; background-color:#CCCCCC" type="text" size="12" name="weekending" value="<%=ldtw%>" onchange="this.form.submit();" readonly/><img alt="popup calendar" src="Images/calendar.jpg" align="center" width="16" height="16" onclick="popUpCalendar(this, routesheet.weekending, 'mm/dd/yyyy')"/> </td> </tr> </table> <table align="center" width="1000" cellspacing="0" cellpadding="0"> <tr bgcolor="black" style="border: 2px solid #FFFFFF"> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Date:</b></font> </td> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Type:</b></font> </td> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Client/Description:</b></font> </td> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Purpose:</b></font> </td> <% if request.querystring("addedit")="edit" Then %> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Add Mileage/Expense:</b></font> </td> <td align="center"> <table> <tr> <td colspan="3"> <font face="Arial" size="2" color="white"><b>Per Diem:</b></font> </td> </tr> <tr> <td> <font face="Arial" size="2" color="white"><b>BKFST</b></font> <font face="Arial" size="2" color="white"><b>LUNCH</b></font> <font face="Arial" size="2" color="white"><b>DINNR</b></font> </td> </tr> </table> </td> <% end if %> </tr> <% for i = 0 to 6 %> <div id="route<%=i%>"> <tr height="50px"> <td width="125px" style="border-bottom:1px solid #000000"> <table> <tr> <td> <input type="image" name="plus<%=i%>" value="plus<%=i%>" src="images/plus.png" alt="Add Another Stop" onclick="addroute(<%=i%>);"/> </td> <td style="text-align: center; width: 100px;"> <font face="Arial" size="2" color="black"/><b><%=WeekdayName(Weekday(fdtw)+i)%></b><br/><font size="1"><%=fdtw+i%></font> <input type="hidden" name="weekday<%=i%>" value="<%=fdtw+i%>"/> </td> </tr> </table> </td> <td style="border-bottom:1px solid #000000; text-align: center;"> <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(<%=i%>);"> <option value="Select">Select Type...</option> <option value="Existing">Existing Client</option> <option value="Prospect">Prospect</option> <option value="Trade">Trade Show</option> <option value="Meeting">Meeting</option> <option value="Office">In Office</option> <option value="Leave">Leave Request</option> </select> </td> <td style="border-bottom:1px solid #000000; text-align: center;"> <div id="leavediv<%=i%>" style="display:none;"> <select name="leave<%=i%>" id="leave<%=i%>"> <option value=""></option> <option value="Vacation">Vacation</option> <option value="Sick">Sick</option> <option value="PersonalLeave">Personal Leave</option> <option value="Birthday">Birthday</option> <option value="Funderal">Funeral</option> <option value="JurtyDuty">Jury Duty</option> </select> <script> var z=dhtmlXComboFromSelect("leave<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script> </div> <div id="meetingdiv<%=i%>" style="display:none;"> <select name="meeting<%=i%>" id="meeting<%=i%>"> <option value=""></option> <% For mlvcounter = 0 to UBound(MeetingListValues,2) %> <option value="<%=(MeetingListValues(MyMeeting_Number,mlvcounter))%>"><%=MeetingListValues(MyMeeting_Desc,mlvcounter)%></option> <% Next %> </select> <script> var z=dhtmlXComboFromSelect("meeting<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script> </div> <div id="clientdiv<%=i%>" style="display:block;"> <select name="client<%=i%>" id="client<%=i%>"> <option value=""></option> <% For rowcounter = 0 To UBound(ClientListValues,2) %> <option value="<%=(ClientListValues(MyClient_Code,rowcounter))%>"><%=ClientListValues(MyClient_FName,rowcounter) & " - " & ClientListValues(MyClient_City,rowcounter) & ", " & ClientListValues(MyClient_State,rowcounter)%></option> <% Next %> </select> <script> var z=dhtmlXComboFromSelect("client<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script> </div> </td> <td style="border-bottom:1px solid #000000; text-align: center;"> <select id="purpose<%=i%>" name="purpose<%=i%>" style="display:block"> <option value="Select">Select Purpose...</option> <option value="Renewal">Renewal</option> <option value="New_Business">New Business</option> <option value="Claim_Related">Claim Related</option> <option value="Annual_Mtg">Annual Meeting</option> <option value="BOD_Review">BOD Review</option> <option value="Other">Other</option> </select> </td> <% if request.querystring("addedit")="edit" Then %> <td style="border-bottom:1px solid #000000; text-align: center;"> <input type="submit" value="Add Exp" name="Expense<%=i%>" onclick="submitexpense(<%=i%>)"/> <input type="submit" value="Add Mlge" name="Mileage<%=i%>" onclick="this.form.action='mileage.asp'"/> </td> <td align="center" style="border-bottom:1px solid #000000"> <table> <tr> <td> <input type="checkbox" name="BKFST<%=i%>"/> </td> <td> <input type="checkbox" name="LUNCH<%=i%>"/> </td> <td> <input type="checkbox" name="DINNR<%=i%>"/> </td> </tr> </table> </td> <% end if %> </tr> </div> <% next %> </table> <table align="center" width="1000" cellspacing="0" cellpadding="0"> <tr align="right"> <td> <br/> <input type="submit" value="Continue..." name="continue" onclick="submitcontinue(<%=i%>)"/> </td> </tr> </table> <input type="hidden" value="" name="subdate"/> <input type="hidden" value="" name="adddate"/> </form> </body> </html>
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <% if request("weekending") <> "" then thisdate = cdate(request("weekending")) thisday = weekday(thisdate) fdtw=dateadd("d", -thisday, thisdate) +1 ldtw=fdtw+6 Else today=weekday(date()) fdtw=dateadd("d", -today, date()) +1 ldtw=fdtw+6 End If %> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> <title>KFSA Route Sheet</title> <script language="javascript" src="modules/popupcal/popcalendarroutesheet.js"> </script> <script src="/modules/combobox/dhtmlxcommon.js"></script> <script src="/modules/combobox/dhtmlxcombo.js"></script> <script src="/modules/combobox/ext/dhtmlxcombo_whp.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="/modules/combobox/dhtmlxcombo.css"/> <script type="text/javascript"> window.dhx_globalImgPath="/modules/combobox/"; </script> <script language="javascript" type="text/javascript"> function submitexpense(thisValue) { document.routesheet.subdate.value=thisValue; document.routesheet.action='expense.asp?addedit=add'; document.routesheet.submit(); } </script> <script language="javascript" type="text/javascript"> function submitcontinue(thisValue) { document.routesheet.subdate.value=thisValue; document.routesheet.action='modules/addroute.asp'; document.routesheet.submit(); } </script> <script language="javascript" type="text/javascript"> function showCols(thisValue) { if (document.getElementById("type"+thisValue).value=="Existing") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } else if (document.getElementById("type"+thisValue).value=="Prospect") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } else if (document.getElementById("type"+thisValue).value=="Trade") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = ''; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; } else if (document.getElementById("type"+thisValue).value=="Meeting") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = ''; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; } else if (document.getElementById("type"+thisValue).value=="Office") { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } else if (document.getElementById("type"+thisValue).value=="Leave") { document.getElementById("leavediv"+thisValue).style.display = ''; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; } else { document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } } </script> </head> <body> <% response.write(request("adddate") & "<br>") 'response.write("First day of this week: " & fdtw & "<br>") 'response.write("Last day of this week: " & ldtw) Set oConn = Server.CreateObject("ADODB.Connection") Set oRS = Server.CreateObject("ADODB.Recordset") oConn.ConnectionString = "DSN=EbixClient;uid=********;pwd=*********" oConn.Open oRS.Open "Select Client_Code, Client_Name, Client_FName, Client_City, Client_State From dbo.Client_List WITH (NOLOCK) ORDER By Client_FName", oConn 'Now, read the Recordset into a 2d array Dim ClientListValues ClientListValues = oRS.GetRows() oRS.Close oRS.Open "Select DISTINCT ACC_DISP_NUMBER, ACC_DESCRIPTION FROM dbo.GL_ACCOUNTS WITH (NOLOCK) WHERE ((ACC_DISP_NUMBER >= 6550.00 AND ACC_DISP_NUMBER <= 6551.00) OR (ACC_DISP_NUMBER >= 6600.00 AND ACC_DISP_NUMBER <= 6601.00)) ORDER By ACC_DESCRIPTION", oConn Dim MeetingListValues MeetingListValues = oRS.GetRows() oRS.Close oConn.Close Set oRS = Nothing Set oConn = Nothing Const MyClient_Code = 0 Const MyClient_Name = 1 Const MyClient_FName = 2 Const MyClient_City = 3 Const MyClient_State = 4 Const MyMeeting_Number = 0 Const MyMeeting_Desc = 1 %> <form name="routesheet" action="" method="post"> <table width="1000" align="center" cellpadding="2" cellspacing="0"> <tr bgcolor="black"> <td border="0"> <font face="arial" size="2" color="white"><b>Travel & Expense Report - KFSA</b></font> </td> <td align="right" border="0"> <font face="arial" size="2" color="white"><b>Route Sheet for <%=Session("fname")%></b></font> </td> </tr> </table> <table align="center"> <tr> <td align=center> <font face=Arial size=2><b>Week Ending: </b></font><input id="we" style="text-align:center; background-color:#CCCCCC" type="text" size="12" name="weekending" value="<%=ldtw%>" onchange="this.form.submit();" readonly/><img alt="popup calendar" src="Images/calendar.jpg" align="center" width="16" height="16" onclick="popUpCalendar(this, routesheet.weekending, 'mm/dd/yyyy')"/> </td> </tr> </table> <table align="center" width="1000" cellspacing="0" cellpadding="0"> <tr bgcolor="black" style="border: 2px solid #FFFFFF"> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Date:</b></font> </td> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Type:</b></font> </td> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Client/Description:</b></font> </td> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Purpose:</b></font> </td> <% if request.querystring("addedit")="edit" Then %> <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF"> <font face="Arial" size="2" color="white"><b>Add Mileage/Expense:</b></font> </td> <td align="center"> <table> <tr> <td colspan="3"> <font face="Arial" size="2" color="white"><b>Per Diem:</b></font> </td> </tr> <tr> <td> <font face="Arial" size="2" color="white"><b>BKFST</b></font> <font face="Arial" size="2" color="white"><b>LUNCH</b></font> <font face="Arial" size="2" color="white"><b>DINNR</b></font> </td> </tr> </table> </td> <% end if %> </tr> <% for i = 0 to 6 %> <div id="route<%=i%>"> <tr height="50px"> <td width="125px" style="border-bottom:1px solid #000000"> <table> <tr> <td> <input type="image" name="plus<%=i%>" value="plus<%=i%>" src="images/plus.png" alt="Add Another Stop" onclick="addroute(<%=i%>);"/> </td> <td style="text-align: center; width: 100px;"> <font face="Arial" size="2" color="black"/><b><%=WeekdayName(Weekday(fdtw)+i)%></b><br/><font size="1"><%=fdtw+i%></font> <input type="hidden" name="weekday<%=i%>" value="<%=fdtw+i%>"/> </td> </tr> </table> </td> <td style="border-bottom:1px solid #000000; text-align: center;"> <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(<%=i%>);"> <option value="Select">Select Type...</option> <option value="Existing">Existing Client</option> <option value="Prospect">Prospect</option> <option value="Trade">Trade Show</option> <option value="Meeting">Meeting</option> <option value="Office">In Office</option> <option value="Leave">Leave Request</option> </select> </td> <td style="border-bottom:1px solid #000000; text-align: center;"> <div id="leavediv<%=i%>" style="display:none;"> <select name="leave<%=i%>" id="leave<%=i%>"> <option value=""></option> <option value="Vacation">Vacation</option> <option value="Sick">Sick</option> <option value="PersonalLeave">Personal Leave</option> <option value="Birthday">Birthday</option> <option value="Funderal">Funeral</option> <option value="JurtyDuty">Jury Duty</option> </select> <script> var z=dhtmlXComboFromSelect("leave<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script> </div> <div id="meetingdiv<%=i%>" style="display:none;"> <select name="meeting<%=i%>" id="meeting<%=i%>"> <option value=""></option> <% For mlvcounter = 0 to UBound(MeetingListValues,2) %> <option value="<%=(MeetingListValues(MyMeeting_Number,mlvcounter))%>"><%=MeetingListValues(MyMeeting_Desc,mlvcounter)%></option> <% Next %> </select> <script> var z=dhtmlXComboFromSelect("meeting<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script> </div> <div id="clientdiv<%=i%>" style="display:block;"> <select name="client<%=i%>" id="client<%=i%>"> <option value=""></option> <% For rowcounter = 0 To UBound(ClientListValues,2) %> <option value="<%=(ClientListValues(MyClient_Code,rowcounter))%>"><%=ClientListValues(MyClient_FName,rowcounter) & " - " & ClientListValues(MyClient_City,rowcounter) & ", " & ClientListValues(MyClient_State,rowcounter)%></option> <% Next %> </select> <script> var z=dhtmlXComboFromSelect("client<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script> </div> </td> <td style="border-bottom:1px solid #000000; text-align: center;"> <select id="purpose<%=i%>" name="purpose<%=i%>" style="display:block"> <option value="Select">Select Purpose...</option> <option value="Renewal">Renewal</option> <option value="New_Business">New Business</option> <option value="Claim_Related">Claim Related</option> <option value="Annual_Mtg">Annual Meeting</option> <option value="BOD_Review">BOD Review</option> <option value="Other">Other</option> </select> </td> <% if request.querystring("addedit")="edit" Then %> <td style="border-bottom:1px solid #000000; text-align: center;"> <input type="submit" value="Add Exp" name="Expense<%=i%>" onclick="submitexpense(<%=i%>)"/> <input type="submit" value="Add Mlge" name="Mileage<%=i%>" onclick="this.form.action='mileage.asp'"/> </td> <td align="center" style="border-bottom:1px solid #000000"> <table> <tr> <td> <input type="checkbox" name="BKFST<%=i%>"/> </td> <td> <input type="checkbox" name="LUNCH<%=i%>"/> </td> <td> <input type="checkbox" name="DINNR<%=i%>"/> </td> </tr> </table> </td> <% end if %> </tr> </div> <% next %> </table> <table align="center" width="1000" cellspacing="0" cellpadding="0"> <tr align="right"> <td> <br/> <input type="submit" value="Continue..." name="continue" onclick="submitcontinue(<%=i%>)"/> </td> </tr> </table> <input type="hidden" value="" name="subdate"/> <input type="hidden" value="" name="adddate"/> </form> </body> </html>
Last edited by peter_budo; Jun 25th, 2009 at 2:20 pm. Reason: Splitting into two sections
JSV,
Firstly, pleeeeeeeease simplify
Unless I've made a mistake, this should do exactly the same job.
Now try this - should be something like what you're looking for:
This is a snippet from the middle of your html.
Notes:
Firstly, pleeeeeeeease simplify
showCols(){} thus: JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function showCols(thisValue) { switch(document.getElementById("type"+thisValue).value){ case "Trade": case "Meeting": document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = ''; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; break; case "Leave": document.getElementById("leavediv"+thisValue).style.display = ''; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = 'none'; document.getElementById("purpose"+thisValue).disabled = true; break; case "Existing": case "Prospect": case "Office": default: document.getElementById("leavediv"+thisValue).style.display = 'none'; document.getElementById("meetingdiv"+thisValue).style.display = 'none'; document.getElementById("clientdiv"+thisValue).style.display = ''; document.getElementById("purpose"+thisValue).disabled = false; } }
Now try this - should be something like what you're looking for:
javascript Syntax (Toggle Plain Text)
function addroute(n){ var day = document.getElementById('day' + n);//Find the <tbody> wrapper for the day in question if(!day || !day.hasChildNodes) { return false; } firstRoute = day.firstChild; while(firstRoute.nodeType !== 1){ firstRoute = firstRoute.nextSibling; }//FF "textnode buster" var newRoute = firstRoute.cloneNode(true);//Clone the first route for the day in question day.tally = (day.tally) ? day.tally++ : 0;//Remember how many routes we have added var suffix = '_' + day.tally;//Compose the id/name suffix renumberIt(newRoute, suffix);//Add suffix to all id and name attributes in the cloned row (to make them unique) var newCells = newRoute.childNodes; for(var i=0; i<newCells.length; i++){ if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = ' '; } } day.appendChild(newRoute); return false;//critical to suppress hyperlink action. } function renumberIt(targetElement, suffix){ if(targetElement.nodeType != 1) { return; } if(targetElement.id) { targetElement.id += suffix; } if(targetElement.name) { targetElement.name += suffix; } var ch = targetElement.childNodes; for(var i=0; i<ch.length; i++){ renumberIt(ch[i], suffix);//drilldown with a recursive call. } }
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
.... <% for i = 0 to 6 %> <tbody id="day<%=i%>" class="day"> <tr height="50px"> <td blankMe="1" width="125px" style="border-bottom:1px solid #000000"> <table> <tr> <td><a href="" alt="Add Another Stop" onclick="return addroute(<%=i%>);"><img src="images/plus.png" border="0" /></a></td> <td style="text-align: center; width: 100px;"> .... .... <% end if %> </tr> </tbody> <% next %> </table> ....
- Use <tbody></tbody> structure within table instead of <div></div>
- <a><img ...></a> instead of <input type="image" ...>
- Give cells whose content you want to be blanked in the new row a custom attribute of blankMe="1"
- Return false from addroute() and hence from its onclick call to suppress hyperlink action (or form submission or whatever).
- Note, embedded javascript in the cloned row will not run.
- Tested staticly (not asp) so not tested with multiple days (0 to 6 i loop)
Last edited by Airshow; Jun 25th, 2009 at 9:57 pm.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Jun 2009
Posts: 18
Reputation:
Solved Threads: 1
Airshow,
Thank you so much for your help. Most of the code that you supplied worked GREAT!! What didn't work was my onchange call
My Combobox under the Client/Description Heading wouldn't show any data at all. I'm wondering if this is becuase the onchange wouldn't work. Is there any way to get this working?
Also, if my embedded javascript won't work, then my combobox won't work will it?
Again, thank you for your time. I really do appreciate it. I'm really javascript illiterate so sorry to be such a pain.
If you would like to see the code again, I am attaching it as code.txt file.
Thank you
Thank you so much for your help. Most of the code that you supplied worked GREAT!! What didn't work was my onchange call
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
onchange="showCols(<%=i%>);
My Combobox under the Client/Description Heading wouldn't show any data at all. I'm wondering if this is becuase the onchange wouldn't work. Is there any way to get this working?
Also, if my embedded javascript won't work, then my combobox won't work will it?
Again, thank you for your time. I really do appreciate it. I'm really javascript illiterate so sorry to be such a pain.
If you would like to see the code again, I am attaching it as code.txt file.
Thank you
Hit any user to continue......
JSV,
>> What didn't work was my onchange call; onchange="showCols(<%=i%>);
I made a teeny-weeny little critical mistake and overlooked something. Try this:
In function addroute:
Add a new javascript function:
And in the HTML
Your "type" combo will now work in cloned rows, which will be reset to neutral settings.
It's also possible that I made a mistake in simplifying
>> My Combobox under the Client/Description Heading wouldn't show any data at all. ...
I'm not sure what's going on here. Options in the "meeting" and "leave" combos are built server-side in ASP loops. As far as I can tell my cloning process should not affect them - they should be perfect clones of those in the served original. If they are not populated, then I have to suggest looking at the ASP. As I said, I am unable to test it.
>> Also, if my embedded javascript won't work, then my combobox won't work will it?
As far as I can tell, the embedded javascript just gives the commboboxes some go-faster stripes. It doesn't affect their options or basic functionality. Besides, the new resetRow function now includes code to mimic the embedded javascript, so the go-faster gizmos should be preserved (untested).
Let me know how it goes
Airshow
>> What didn't work was my onchange call; onchange="showCols(<%=i%>);
I made a teeny-weeny little critical mistake and overlooked something. Try this:
In function addroute:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
//--Find // day.tally = (day.tally) ? day.tally++ : 0;//Remember how many routes we have added //--replace with day.tally = (typeof day.tally == 'undefined') ? 0 : day.tally+1;//Remember how many routes we have added //--Find // if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = ' '; } //--Replace with try{ if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = ' '; } }//Necessary in FF catch(e){ ; } //--Find // day.appendChild(newRoute); //--add after resetRow(newRoute, n, suffix);
javascript Syntax (Toggle Plain Text)
function resetRow(row, n, suffix){ var selects = row.getElementsByTagName('select'); for(var i=0; i<selects.length; i++){ selects[i].selectedIndex = 0; var baseName = selects[i].id.replace(n + suffix, ''); switch(baseName){ case ('leave'): case ('meeting'): case ('client'): try{ var z=dhtmlXComboFromSelect(x + n + suffix,200); z.enableFilteringMode(true); z.setOptionWidth(450); } catch(e){ ; } break; default: //Do nothing } } var inputs = row.getElementsByTagName('input'); for(var i=0; i<inputs.length; i++){ switch(inputs[i].type.toLowerCase()){ case 'checkbox': inputs[i].checked = 0; break; default: //Do nothing } } showCols(n + suffix); }
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
//--Find <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(<%=i%>);"> //--Replace with <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(this.getAttribute('id').replace('type', ''));"> //--(This is messy but gets the job done)
It's also possible that I made a mistake in simplifying
showcols . If so, then it will misbehave on your original rows as well as cloned rows. I think your original showcols will still work but try my changes first because I think my simplified showcols is OK.>> My Combobox under the Client/Description Heading wouldn't show any data at all. ...
I'm not sure what's going on here. Options in the "meeting" and "leave" combos are built server-side in ASP loops. As far as I can tell my cloning process should not affect them - they should be perfect clones of those in the served original. If they are not populated, then I have to suggest looking at the ASP. As I said, I am unable to test it.
>> Also, if my embedded javascript won't work, then my combobox won't work will it?
As far as I can tell, the embedded javascript just gives the commboboxes some go-faster stripes. It doesn't affect their options or basic functionality. Besides, the new resetRow function now includes code to mimic the embedded javascript, so the go-faster gizmos should be preserved (untested).
Let me know how it goes
Airshow
Last edited by Airshow; Jun 28th, 2009 at 11:44 am. Reason: Typos
50% of the solution lies in accurately describing the problem!
>> can I put a [-] next to the newly created rows in order to delete
Yes but there are implications server-side.
As it stands (without a delete function), it is fairly easy server-side to find which name|value pairs have been submitted in the POST. Names in cloned rows will have _n appended to their baserow's names, so you can loop through with an integer counter and when you find name_n is not set, then the code can be certain that there are no more rows.
Now, say a cloned row was deleted. When you find name_n is not set, there is no longer certainty that there are no more rows.
If you want to delete rows, then either your paradigm for retreiving POST data must be a bit cleverer or you need to take measures client-side to "close the numbering gap" when a row is deleted.
Airshow
Yes but there are implications server-side.
As it stands (without a delete function), it is fairly easy server-side to find which name|value pairs have been submitted in the POST. Names in cloned rows will have _n appended to their baserow's names, so you can loop through with an integer counter and when you find name_n is not set, then the code can be certain that there are no more rows.
Now, say a cloned row was deleted. When you find name_n is not set, there is no longer certainty that there are no more rows.
If you want to delete rows, then either your paradigm for retreiving POST data must be a bit cleverer or you need to take measures client-side to "close the numbering gap" when a row is deleted.
Airshow
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Jun 2009
Posts: 18
Reputation:
Solved Threads: 1
Airshow,
Thank you again for the new code, most of it is working now. On the cloned rows, it is still not populating the Client/Description combobox. The combobox is populated on the main row, so the only thing that I can think of is the javascript. When I get the records to populate that combobox from the database, I am putting the data into an asp array. Should I try to put this data into a javascript array instead? Would that help? The other comboboxes are populated statically so I am thinking it has something to do with the array.
Here is the code for the array in asp --
Also, don't know if you saw my other post about removing the newly created rows. Can we put a [-] next to each row so in case they added a row that they don't need, they can click on that to delete it.
I really appreciate all the time you have put into this. I hope you can help me with the next problem.
Thank you again for the new code, most of it is working now. On the cloned rows, it is still not populating the Client/Description combobox. The combobox is populated on the main row, so the only thing that I can think of is the javascript. When I get the records to populate that combobox from the database, I am putting the data into an asp array. Should I try to put this data into a javascript array instead? Would that help? The other comboboxes are populated statically so I am thinking it has something to do with the array.
Here is the code for the array in asp --
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<select name="client<%=i%>" id="client<%=i%>"> <option value=""></option> <% For rowcounter = 0 To UBound(ClientListValues,2) %> <option value="<%=(ClientListValues(MyClient_Code,rowcounter))%>"><%=ClientListValues(MyClient_FName,rowcounter) & " - " & ClientListValues(MyClient_City,rowcounter) & ", " & ClientListValues(MyClient_State,rowcounter)%></option> <% Next %> </select> <script> var z=dhtmlXComboFromSelect("client<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script>
Also, don't know if you saw my other post about removing the newly created rows. Can we put a [-] next to each row so in case they added a row that they don't need, they can click on that to delete it.
I really appreciate all the time you have put into this. I hope you can help me with the next problem.
Hit any user to continue......
•
•
Join Date: Jun 2009
Posts: 18
Reputation:
Solved Threads: 1
Sorry, didn't see the post about the deleting of the row. If you can supply the code to remove that would be great. When the data gets posted, I am going to put it all into an array so when I go through the posted information, the array will find all information and return the amount in the array, so it shouldn't be a problem if the numbers aren't consecutive.
Thank you again.
Thank you again.
Hit any user to continue......
JSV,
OK, here's the remove code.
Of course, that pretty well makes a nonsense of the custom attribute "blankMe". The code won't mind but something like "convertMe" would be more appropriate now.
Airshow
OK, here's the remove code.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
//--Find if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = ' '; } //--replace with if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = makeDeleteButton(n, suffix); } //--Add new functions function deleteRoute(suffix){ var id = "baseRoute" + suffix; var node = document.getElementById(id); if(!node) { return; } node.parentNode.removeChild(node); } function makeDeleteButton(n, suffix){ return ['<a href="#" onclick="return deleteRoute(\'', (n + suffix), '\')"><img src="images/minus.png" border="0"></a>'].join(''); }
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
//--Find <tr height="50px"> //--replace with <tr id="baseRoute<%=i%>" height="50px">
Airshow
Last edited by Airshow; Jun 28th, 2009 at 4:17 pm.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Jun 2009
Posts: 18
Reputation:
Solved Threads: 1
I finally figured out why the cloned rows won't populate the combobox. This code is the culprit:
If I take out this code, then everything works correctly. My problem is that this code allows me to type in new values in the dropdown boxes so if they option that they want isn't available, or it is a new option, then they can just type something in. It also allows me to format the dropdown boxes so that they look nice on the page.
Any ideas?
Thanks. Also, thanks for the delete code, I really appreciate everything that you have done to help me with this project.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script> var z=dhtmlXComboFromSelect("leave<%=i%>",200); z.enableFilteringMode(true); z.setOptionWidth(450); </script>
If I take out this code, then everything works correctly. My problem is that this code allows me to type in new values in the dropdown boxes so if they option that they want isn't available, or it is a new option, then they can just type something in. It also allows me to format the dropdown boxes so that they look nice on the page.
Any ideas?
Thanks. Also, thanks for the delete code, I really appreciate everything that you have done to help me with this project.
Hit any user to continue......
![]() |
Similar Threads
- Adding a new row in a Datagrid ??????????? (C#)
- Adding new row in DataGrid (C#)
- adding controls dynamically (VB.NET)
- Having problems with adding a row to a DataSet (VB.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Help with javascript regular expressions
- Next Thread: Problem facing in removing space in page between table???
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom download dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security select shopping size software unicode w3c web wysiwyg \n





