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
Reply

Join Date: Jun 2009
Posts: 18
Reputation: jsvanc is an unknown quantity at this point 
Solved Threads: 1
jsvanc jsvanc is offline Offline
Newbie Poster

Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #1
Jun 24th, 2009
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)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4. <head>
  5. <%
  6. if request("weekending") <> "" then
  7. thisdate = cdate(request("weekending"))
  8. thisday = weekday(thisdate)
  9. fdtw=dateadd("d", -thisday, thisdate) +1
  10. ldtw=fdtw+6
  11. Else
  12. today=weekday(date())
  13. fdtw=dateadd("d", -today, date()) +1
  14. ldtw=fdtw+6
  15. End If
  16. %>
  17. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
  18. <title>KFSA Route Sheet</title>
  19. <script language="javascript" src="modules/popupcal/popcalendarroutesheet.js">
  20. </script>
  21.  
  22. <script src="/modules/combobox/dhtmlxcommon.js"></script>
  23. <script src="/modules/combobox/dhtmlxcombo.js"></script>
  24. <script src="/modules/combobox/ext/dhtmlxcombo_whp.js" type="text/javascript"></script>
  25. <link rel="stylesheet" type="text/css" href="/modules/combobox/dhtmlxcombo.css"/>
  26. <script type="text/javascript">
  27. window.dhx_globalImgPath="/modules/combobox/";
  28. </script>
  29. <script language="javascript" type="text/javascript">
  30. function submitexpense(thisValue) {
  31. document.routesheet.subdate.value=thisValue;
  32. document.routesheet.action='expense.asp?addedit=add';
  33. document.routesheet.submit();
  34. }
  35. </script>
  36. <script language="javascript" type="text/javascript">
  37. function submitcontinue(thisValue) {
  38. document.routesheet.subdate.value=thisValue;
  39. document.routesheet.action='modules/addroute.asp';
  40. document.routesheet.submit();
  41. }
  42. </script>
  43. <script language="javascript" type="text/javascript">
  44. function showCols(thisValue) {
  45. if (document.getElementById("type"+thisValue).value=="Existing") {
  46. document.getElementById("leavediv"+thisValue).style.display = 'none';
  47. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  48. document.getElementById("clientdiv"+thisValue).style.display = '';
  49. document.getElementById("purpose"+thisValue).disabled = false;
  50. }
  51. else if (document.getElementById("type"+thisValue).value=="Prospect") {
  52. document.getElementById("leavediv"+thisValue).style.display = 'none';
  53. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  54. document.getElementById("clientdiv"+thisValue).style.display = '';
  55. document.getElementById("purpose"+thisValue).disabled = false;
  56. }
  57. else if (document.getElementById("type"+thisValue).value=="Trade") {
  58. document.getElementById("leavediv"+thisValue).style.display = 'none';
  59. document.getElementById("meetingdiv"+thisValue).style.display = '';
  60. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  61. document.getElementById("purpose"+thisValue).disabled = true;
  62. }
  63. else if (document.getElementById("type"+thisValue).value=="Meeting") {
  64. document.getElementById("leavediv"+thisValue).style.display = 'none';
  65. document.getElementById("meetingdiv"+thisValue).style.display = '';
  66. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  67. document.getElementById("purpose"+thisValue).disabled = true;
  68. }
  69. else if (document.getElementById("type"+thisValue).value=="Office") {
  70. document.getElementById("leavediv"+thisValue).style.display = 'none';
  71. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  72. document.getElementById("clientdiv"+thisValue).style.display = '';
  73. document.getElementById("purpose"+thisValue).disabled = false;
  74. }
  75. else if (document.getElementById("type"+thisValue).value=="Leave") {
  76. document.getElementById("leavediv"+thisValue).style.display = '';
  77. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  78. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  79. document.getElementById("purpose"+thisValue).disabled = true;
  80. }
  81. else {
  82. document.getElementById("leavediv"+thisValue).style.display = 'none';
  83. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  84. document.getElementById("clientdiv"+thisValue).style.display = '';
  85. document.getElementById("purpose"+thisValue).disabled = false;
  86. }
  87. }
  88. </script>
  89.  
  90. </head>
  91.  
  92. <body>
  93. <%
  94. response.write(request("adddate") & "<br>")
  95. 'response.write("First day of this week: " & fdtw & "<br>")
  96. 'response.write("Last day of this week: " & ldtw)
  97.  
  98. Set oConn = Server.CreateObject("ADODB.Connection")
  99. Set oRS = Server.CreateObject("ADODB.Recordset")
  100.  
  101. oConn.ConnectionString = "DSN=EbixClient;uid=********;pwd=*********"
  102.  
  103. oConn.Open
  104. oRS.Open "Select Client_Code, Client_Name, Client_FName, Client_City, Client_State From dbo.Client_List WITH (NOLOCK) ORDER By Client_FName", oConn
  105.  
  106. 'Now, read the Recordset into a 2d array
  107. Dim ClientListValues
  108. ClientListValues = oRS.GetRows()
  109.  
  110. oRS.Close
  111.  
  112. 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
  113.  
  114. Dim MeetingListValues
  115. MeetingListValues = oRS.GetRows()
  116.  
  117. oRS.Close
  118. oConn.Close
  119. Set oRS = Nothing
  120. Set oConn = Nothing
  121.  
  122. Const MyClient_Code = 0
  123. Const MyClient_Name = 1
  124. Const MyClient_FName = 2
  125. Const MyClient_City = 3
  126. Const MyClient_State = 4
  127.  
  128. Const MyMeeting_Number = 0
  129. Const MyMeeting_Desc = 1
  130. %>
  131. <form name="routesheet" action="" method="post">
  132. <table width="1000" align="center" cellpadding="2" cellspacing="0">
  133. <tr bgcolor="black">
  134. <td border="0">
  135. <font face="arial" size="2" color="white"><b>Travel & Expense Report - KFSA</b></font>
  136. </td>
  137. <td align="right" border="0">
  138. <font face="arial" size="2" color="white"><b>Route Sheet for <%=Session("fname")%></b></font>
  139. </td>
  140. </tr>
  141. </table>
  142. <table align="center">
  143. <tr>
  144. <td align=center>
  145. <font face=Arial size=2><b>Week Ending:&nbsp;&nbsp;</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')"/>
  146. </td>
  147. </tr>
  148. </table>
  149. <table align="center" width="1000" cellspacing="0" cellpadding="0">
  150. <tr bgcolor="black" style="border: 2px solid #FFFFFF">
  151. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  152. <font face="Arial" size="2" color="white"><b>Date:</b></font>
  153. </td>
  154. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  155. <font face="Arial" size="2" color="white"><b>Type:</b></font>
  156. </td>
  157. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  158. <font face="Arial" size="2" color="white"><b>Client/Description:</b></font>
  159. </td>
  160. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  161. <font face="Arial" size="2" color="white"><b>Purpose:</b></font>
  162. </td>
  163. <% if request.querystring("addedit")="edit" Then %>
  164. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  165. <font face="Arial" size="2" color="white"><b>Add Mileage/Expense:</b></font>
  166. </td>
  167. <td align="center">
  168. <table>
  169. <tr>
  170. <td colspan="3">
  171. <font face="Arial" size="2" color="white"><b>Per Diem:</b></font>
  172. </td>
  173. </tr>
  174. <tr>
  175. <td>
  176. <font face="Arial" size="2" color="white"><b>BKFST</b></font>
  177. <font face="Arial" size="2" color="white"><b>LUNCH</b></font>
  178. <font face="Arial" size="2" color="white"><b>DINNR</b></font>
  179. </td>
  180. </tr>
  181. </table>
  182. </td>
  183. <% end if %>
  184. </tr>
  185. <% for i = 0 to 6 %>
  186. <div id="route<%=i%>">
  187. <tr height="50px">
  188. <td width="125px" style="border-bottom:1px solid #000000">
  189. <table>
  190. <tr>
  191. <td>
  192. <input type="image" name="plus<%=i%>" value="plus<%=i%>" src="images/plus.png" alt="Add Another Stop" onclick="addroute(<%=i%>);"/>
  193. </td>
  194. <td style="text-align: center; width: 100px;">
  195. <font face="Arial" size="2" color="black"/><b><%=WeekdayName(Weekday(fdtw)+i)%></b><br/><font size="1"><%=fdtw+i%></font>
  196. <input type="hidden" name="weekday<%=i%>" value="<%=fdtw+i%>"/>
  197. </td>
  198. </tr>
  199. </table>
  200. </td>
  201. <td style="border-bottom:1px solid #000000; text-align: center;">
  202. <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(<%=i%>);">
  203. <option value="Select">Select Type...</option>
  204. <option value="Existing">Existing Client</option>
  205. <option value="Prospect">Prospect</option>
  206. <option value="Trade">Trade Show</option>
  207. <option value="Meeting">Meeting</option>
  208. <option value="Office">In Office</option>
  209. <option value="Leave">Leave Request</option>
  210. </select>
  211. </td>
  212. <td style="border-bottom:1px solid #000000; text-align: center;">
  213. <div id="leavediv<%=i%>" style="display:none;">
  214. <select name="leave<%=i%>" id="leave<%=i%>">
  215. <option value=""></option>
  216. <option value="Vacation">Vacation</option>
  217. <option value="Sick">Sick</option>
  218. <option value="PersonalLeave">Personal Leave</option>
  219. <option value="Birthday">Birthday</option>
  220. <option value="Funderal">Funeral</option>
  221. <option value="JurtyDuty">Jury Duty</option>
  222. </select>
  223. <script>
  224. var z=dhtmlXComboFromSelect("leave<%=i%>",200);
  225. z.enableFilteringMode(true);
  226. z.setOptionWidth(450);
  227. </script>
  228. </div>
  229. <div id="meetingdiv<%=i%>" style="display:none;">
  230. <select name="meeting<%=i%>" id="meeting<%=i%>">
  231. <option value=""></option>
  232. <% For mlvcounter = 0 to UBound(MeetingListValues,2) %>
  233. <option value="<%=(MeetingListValues(MyMeeting_Number,mlvcounter))%>"><%=MeetingListValues(MyMeeting_Desc,mlvcounter)%></option>
  234. <% Next %>
  235. </select>
  236. <script>
  237. var z=dhtmlXComboFromSelect("meeting<%=i%>",200);
  238. z.enableFilteringMode(true);
  239. z.setOptionWidth(450);
  240. </script>
  241. </div>
  242. <div id="clientdiv<%=i%>" style="display:block;">
  243. <select name="client<%=i%>" id="client<%=i%>">
  244. <option value=""></option>
  245. <% For rowcounter = 0 To UBound(ClientListValues,2) %>
  246. <option value="<%=(ClientListValues(MyClient_Code,rowcounter))%>"><%=ClientListValues(MyClient_FName,rowcounter) & " - " & ClientListValues(MyClient_City,rowcounter) & ", " & ClientListValues(MyClient_State,rowcounter)%></option>
  247. <% Next %>
  248. </select>
  249. <script>
  250. var z=dhtmlXComboFromSelect("client<%=i%>",200);
  251. z.enableFilteringMode(true);
  252. z.setOptionWidth(450);
  253. </script>
  254. </div>
  255. </td>
  256. <td style="border-bottom:1px solid #000000; text-align: center;">
  257. <select id="purpose<%=i%>" name="purpose<%=i%>" style="display:block">
  258. <option value="Select">Select Purpose...</option>
  259. <option value="Renewal">Renewal</option>
  260. <option value="New_Business">New Business</option>
  261. <option value="Claim_Related">Claim Related</option>
  262. <option value="Annual_Mtg">Annual Meeting</option>
  263. <option value="BOD_Review">BOD Review</option>
  264. <option value="Other">Other</option>
  265. </select>
  266. </td>
  267. <% if request.querystring("addedit")="edit" Then %>
  268. <td style="border-bottom:1px solid #000000; text-align: center;">
  269. <input type="submit" value="Add Exp" name="Expense<%=i%>" onclick="submitexpense(<%=i%>)"/>&nbsp;&nbsp;
  270. <input type="submit" value="Add Mlge" name="Mileage<%=i%>" onclick="this.form.action='mileage.asp'"/>
  271. </td>
  272. <td align="center" style="border-bottom:1px solid #000000">
  273. <table>
  274. <tr>
  275. <td>
  276. <input type="checkbox" name="BKFST<%=i%>"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  277. </td>
  278. <td>
  279. <input type="checkbox" name="LUNCH<%=i%>"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  280. </td>
  281. <td>
  282. <input type="checkbox" name="DINNR<%=i%>"/>
  283. </td>
  284. </tr>
  285. </table>
  286. </td>
  287. <% end if %>
  288. </tr>
  289. </div>
  290. <% next %>
  291. </table>
  292. <table align="center" width="1000" cellspacing="0" cellpadding="0">
  293. <tr align="right">
  294. <td>
  295. &nbsp;<br/>
  296. <input type="submit" value="Continue..." name="continue" onclick="submitcontinue(<%=i%>)"/>
  297. </td>
  298. </tr>
  299. </table>
  300. <input type="hidden" value="" name="subdate"/>
  301. <input type="hidden" value="" name="adddate"/>
  302. </form>
  303. </body>
  304.  
  305. </html>
  306.  

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4. <head>
  5. <%
  6. if request("weekending") <> "" then
  7. thisdate = cdate(request("weekending"))
  8. thisday = weekday(thisdate)
  9. fdtw=dateadd("d", -thisday, thisdate) +1
  10. ldtw=fdtw+6
  11. Else
  12. today=weekday(date())
  13. fdtw=dateadd("d", -today, date()) +1
  14. ldtw=fdtw+6
  15. End If
  16. %>
  17. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
  18. <title>KFSA Route Sheet</title>
  19. <script language="javascript" src="modules/popupcal/popcalendarroutesheet.js">
  20. </script>
  21.  
  22. <script src="/modules/combobox/dhtmlxcommon.js"></script>
  23. <script src="/modules/combobox/dhtmlxcombo.js"></script>
  24. <script src="/modules/combobox/ext/dhtmlxcombo_whp.js" type="text/javascript"></script>
  25. <link rel="stylesheet" type="text/css" href="/modules/combobox/dhtmlxcombo.css"/>
  26. <script type="text/javascript">
  27. window.dhx_globalImgPath="/modules/combobox/";
  28. </script>
  29. <script language="javascript" type="text/javascript">
  30. function submitexpense(thisValue) {
  31. document.routesheet.subdate.value=thisValue;
  32. document.routesheet.action='expense.asp?addedit=add';
  33. document.routesheet.submit();
  34. }
  35. </script>
  36. <script language="javascript" type="text/javascript">
  37. function submitcontinue(thisValue) {
  38. document.routesheet.subdate.value=thisValue;
  39. document.routesheet.action='modules/addroute.asp';
  40. document.routesheet.submit();
  41. }
  42. </script>
  43. <script language="javascript" type="text/javascript">
  44. function showCols(thisValue) {
  45. if (document.getElementById("type"+thisValue).value=="Existing") {
  46. document.getElementById("leavediv"+thisValue).style.display = 'none';
  47. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  48. document.getElementById("clientdiv"+thisValue).style.display = '';
  49. document.getElementById("purpose"+thisValue).disabled = false;
  50. }
  51. else if (document.getElementById("type"+thisValue).value=="Prospect") {
  52. document.getElementById("leavediv"+thisValue).style.display = 'none';
  53. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  54. document.getElementById("clientdiv"+thisValue).style.display = '';
  55. document.getElementById("purpose"+thisValue).disabled = false;
  56. }
  57. else if (document.getElementById("type"+thisValue).value=="Trade") {
  58. document.getElementById("leavediv"+thisValue).style.display = 'none';
  59. document.getElementById("meetingdiv"+thisValue).style.display = '';
  60. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  61. document.getElementById("purpose"+thisValue).disabled = true;
  62. }
  63. else if (document.getElementById("type"+thisValue).value=="Meeting") {
  64. document.getElementById("leavediv"+thisValue).style.display = 'none';
  65. document.getElementById("meetingdiv"+thisValue).style.display = '';
  66. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  67. document.getElementById("purpose"+thisValue).disabled = true;
  68. }
  69. else if (document.getElementById("type"+thisValue).value=="Office") {
  70. document.getElementById("leavediv"+thisValue).style.display = 'none';
  71. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  72. document.getElementById("clientdiv"+thisValue).style.display = '';
  73. document.getElementById("purpose"+thisValue).disabled = false;
  74. }
  75. else if (document.getElementById("type"+thisValue).value=="Leave") {
  76. document.getElementById("leavediv"+thisValue).style.display = '';
  77. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  78. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  79. document.getElementById("purpose"+thisValue).disabled = true;
  80. }
  81. else {
  82. document.getElementById("leavediv"+thisValue).style.display = 'none';
  83. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  84. document.getElementById("clientdiv"+thisValue).style.display = '';
  85. document.getElementById("purpose"+thisValue).disabled = false;
  86. }
  87. }
  88. </script>
  89.  
  90. </head>
  91.  
  92. <body>
  93. <%
  94. response.write(request("adddate") & "<br>")
  95. 'response.write("First day of this week: " & fdtw & "<br>")
  96. 'response.write("Last day of this week: " & ldtw)
  97.  
  98. Set oConn = Server.CreateObject("ADODB.Connection")
  99. Set oRS = Server.CreateObject("ADODB.Recordset")
  100.  
  101. oConn.ConnectionString = "DSN=EbixClient;uid=********;pwd=*********"
  102.  
  103. oConn.Open
  104. oRS.Open "Select Client_Code, Client_Name, Client_FName, Client_City, Client_State From dbo.Client_List WITH (NOLOCK) ORDER By Client_FName", oConn
  105.  
  106. 'Now, read the Recordset into a 2d array
  107. Dim ClientListValues
  108. ClientListValues = oRS.GetRows()
  109.  
  110. oRS.Close
  111.  
  112. 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
  113.  
  114. Dim MeetingListValues
  115. MeetingListValues = oRS.GetRows()
  116.  
  117. oRS.Close
  118. oConn.Close
  119. Set oRS = Nothing
  120. Set oConn = Nothing
  121.  
  122. Const MyClient_Code = 0
  123. Const MyClient_Name = 1
  124. Const MyClient_FName = 2
  125. Const MyClient_City = 3
  126. Const MyClient_State = 4
  127.  
  128. Const MyMeeting_Number = 0
  129. Const MyMeeting_Desc = 1
  130. %>
  131. <form name="routesheet" action="" method="post">
  132. <table width="1000" align="center" cellpadding="2" cellspacing="0">
  133. <tr bgcolor="black">
  134. <td border="0">
  135. <font face="arial" size="2" color="white"><b>Travel & Expense Report - KFSA</b></font>
  136. </td>
  137. <td align="right" border="0">
  138. <font face="arial" size="2" color="white"><b>Route Sheet for <%=Session("fname")%></b></font>
  139. </td>
  140. </tr>
  141. </table>
  142. <table align="center">
  143. <tr>
  144. <td align=center>
  145. <font face=Arial size=2><b>Week Ending:&nbsp;&nbsp;</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')"/>
  146. </td>
  147. </tr>
  148. </table>
  149. <table align="center" width="1000" cellspacing="0" cellpadding="0">
  150. <tr bgcolor="black" style="border: 2px solid #FFFFFF">
  151. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  152. <font face="Arial" size="2" color="white"><b>Date:</b></font>
  153. </td>
  154. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  155. <font face="Arial" size="2" color="white"><b>Type:</b></font>
  156. </td>
  157. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  158. <font face="Arial" size="2" color="white"><b>Client/Description:</b></font>
  159. </td>
  160. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  161. <font face="Arial" size="2" color="white"><b>Purpose:</b></font>
  162. </td>
  163. <% if request.querystring("addedit")="edit" Then %>
  164. <td align="center" valign="bottom" style="border-right-style: solid; border-width: 2px; border-color: #FFFFFF">
  165. <font face="Arial" size="2" color="white"><b>Add Mileage/Expense:</b></font>
  166. </td>
  167. <td align="center">
  168. <table>
  169. <tr>
  170. <td colspan="3">
  171. <font face="Arial" size="2" color="white"><b>Per Diem:</b></font>
  172. </td>
  173. </tr>
  174. <tr>
  175. <td>
  176. <font face="Arial" size="2" color="white"><b>BKFST</b></font>
  177. <font face="Arial" size="2" color="white"><b>LUNCH</b></font>
  178. <font face="Arial" size="2" color="white"><b>DINNR</b></font>
  179. </td>
  180. </tr>
  181. </table>
  182. </td>
  183. <% end if %>
  184. </tr>
  185. <% for i = 0 to 6 %>
  186. <div id="route<%=i%>">
  187. <tr height="50px">
  188. <td width="125px" style="border-bottom:1px solid #000000">
  189. <table>
  190. <tr>
  191. <td>
  192. <input type="image" name="plus<%=i%>" value="plus<%=i%>" src="images/plus.png" alt="Add Another Stop" onclick="addroute(<%=i%>);"/>
  193. </td>
  194. <td style="text-align: center; width: 100px;">
  195. <font face="Arial" size="2" color="black"/><b><%=WeekdayName(Weekday(fdtw)+i)%></b><br/><font size="1"><%=fdtw+i%></font>
  196. <input type="hidden" name="weekday<%=i%>" value="<%=fdtw+i%>"/>
  197. </td>
  198. </tr>
  199. </table>
  200. </td>
  201. <td style="border-bottom:1px solid #000000; text-align: center;">
  202. <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(<%=i%>);">
  203. <option value="Select">Select Type...</option>
  204. <option value="Existing">Existing Client</option>
  205. <option value="Prospect">Prospect</option>
  206. <option value="Trade">Trade Show</option>
  207. <option value="Meeting">Meeting</option>
  208. <option value="Office">In Office</option>
  209. <option value="Leave">Leave Request</option>
  210. </select>
  211. </td>
  212. <td style="border-bottom:1px solid #000000; text-align: center;">
  213. <div id="leavediv<%=i%>" style="display:none;">
  214. <select name="leave<%=i%>" id="leave<%=i%>">
  215. <option value=""></option>
  216. <option value="Vacation">Vacation</option>
  217. <option value="Sick">Sick</option>
  218. <option value="PersonalLeave">Personal Leave</option>
  219. <option value="Birthday">Birthday</option>
  220. <option value="Funderal">Funeral</option>
  221. <option value="JurtyDuty">Jury Duty</option>
  222. </select>
  223. <script>
  224. var z=dhtmlXComboFromSelect("leave<%=i%>",200);
  225. z.enableFilteringMode(true);
  226. z.setOptionWidth(450);
  227. </script>
  228. </div>
  229. <div id="meetingdiv<%=i%>" style="display:none;">
  230. <select name="meeting<%=i%>" id="meeting<%=i%>">
  231. <option value=""></option>
  232. <% For mlvcounter = 0 to UBound(MeetingListValues,2) %>
  233. <option value="<%=(MeetingListValues(MyMeeting_Number,mlvcounter))%>"><%=MeetingListValues(MyMeeting_Desc,mlvcounter)%></option>
  234. <% Next %>
  235. </select>
  236. <script>
  237. var z=dhtmlXComboFromSelect("meeting<%=i%>",200);
  238. z.enableFilteringMode(true);
  239. z.setOptionWidth(450);
  240. </script>
  241. </div>
  242. <div id="clientdiv<%=i%>" style="display:block;">
  243. <select name="client<%=i%>" id="client<%=i%>">
  244. <option value=""></option>
  245. <% For rowcounter = 0 To UBound(ClientListValues,2) %>
  246. <option value="<%=(ClientListValues(MyClient_Code,rowcounter))%>"><%=ClientListValues(MyClient_FName,rowcounter) & " - " & ClientListValues(MyClient_City,rowcounter) & ", " & ClientListValues(MyClient_State,rowcounter)%></option>
  247. <% Next %>
  248. </select>
  249. <script>
  250. var z=dhtmlXComboFromSelect("client<%=i%>",200);
  251. z.enableFilteringMode(true);
  252. z.setOptionWidth(450);
  253. </script>
  254. </div>
  255. </td>
  256. <td style="border-bottom:1px solid #000000; text-align: center;">
  257. <select id="purpose<%=i%>" name="purpose<%=i%>" style="display:block">
  258. <option value="Select">Select Purpose...</option>
  259. <option value="Renewal">Renewal</option>
  260. <option value="New_Business">New Business</option>
  261. <option value="Claim_Related">Claim Related</option>
  262. <option value="Annual_Mtg">Annual Meeting</option>
  263. <option value="BOD_Review">BOD Review</option>
  264. <option value="Other">Other</option>
  265. </select>
  266. </td>
  267. <% if request.querystring("addedit")="edit" Then %>
  268. <td style="border-bottom:1px solid #000000; text-align: center;">
  269. <input type="submit" value="Add Exp" name="Expense<%=i%>" onclick="submitexpense(<%=i%>)"/>&nbsp;&nbsp;
  270. <input type="submit" value="Add Mlge" name="Mileage<%=i%>" onclick="this.form.action='mileage.asp'"/>
  271. </td>
  272. <td align="center" style="border-bottom:1px solid #000000">
  273. <table>
  274. <tr>
  275. <td>
  276. <input type="checkbox" name="BKFST<%=i%>"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  277. </td>
  278. <td>
  279. <input type="checkbox" name="LUNCH<%=i%>"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  280. </td>
  281. <td>
  282. <input type="checkbox" name="DINNR<%=i%>"/>
  283. </td>
  284. </tr>
  285. </table>
  286. </td>
  287. <% end if %>
  288. </tr>
  289. </div>
  290. <% next %>
  291. </table>
  292. <table align="center" width="1000" cellspacing="0" cellpadding="0">
  293. <tr align="right">
  294. <td>
  295. &nbsp;<br/>
  296. <input type="submit" value="Continue..." name="continue" onclick="submitcontinue(<%=i%>)"/>
  297. </td>
  298. </tr>
  299. </table>
  300. <input type="hidden" value="" name="subdate"/>
  301. <input type="hidden" value="" name="adddate"/>
  302. </form>
  303. </body>
  304.  
  305. </html>
  306.  
Last edited by peter_budo; Jun 25th, 2009 at 2:20 pm. Reason: Splitting into two sections
Attached Thumbnails
routesheet.jpg   routesheet1.jpg  
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #2
Jun 25th, 2009
JSV,

Firstly, pleeeeeeeease simplify showCols(){} thus:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function showCols(thisValue) {
  2. switch(document.getElementById("type"+thisValue).value){
  3. case "Trade":
  4. case "Meeting":
  5. document.getElementById("leavediv"+thisValue).style.display = 'none';
  6. document.getElementById("meetingdiv"+thisValue).style.display = '';
  7. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  8. document.getElementById("purpose"+thisValue).disabled = true;
  9. break;
  10. case "Leave":
  11. document.getElementById("leavediv"+thisValue).style.display = '';
  12. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  13. document.getElementById("clientdiv"+thisValue).style.display = 'none';
  14. document.getElementById("purpose"+thisValue).disabled = true;
  15. break;
  16. case "Existing":
  17. case "Prospect":
  18. case "Office":
  19. default:
  20. document.getElementById("leavediv"+thisValue).style.display = 'none';
  21. document.getElementById("meetingdiv"+thisValue).style.display = 'none';
  22. document.getElementById("clientdiv"+thisValue).style.display = '';
  23. document.getElementById("purpose"+thisValue).disabled = false;
  24. }
  25. }
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:
  1. function addroute(n){
  2. var day = document.getElementById('day' + n);//Find the <tbody> wrapper for the day in question
  3. if(!day || !day.hasChildNodes) { return false; }
  4. firstRoute = day.firstChild;
  5. while(firstRoute.nodeType !== 1){ firstRoute = firstRoute.nextSibling; }//FF "textnode buster"
  6. var newRoute = firstRoute.cloneNode(true);//Clone the first route for the day in question
  7. day.tally = (day.tally) ? day.tally++ : 0;//Remember how many routes we have added
  8. var suffix = '_' + day.tally;//Compose the id/name suffix
  9. renumberIt(newRoute, suffix);//Add suffix to all id and name attributes in the cloned row (to make them unique)
  10. var newCells = newRoute.childNodes;
  11. for(var i=0; i<newCells.length; i++){
  12. if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = '&nbsp;'; }
  13. }
  14. day.appendChild(newRoute);
  15. return false;//critical to suppress hyperlink action.
  16. }
  17. function renumberIt(targetElement, suffix){
  18. if(targetElement.nodeType != 1) { return; }
  19. if(targetElement.id) { targetElement.id += suffix; }
  20. if(targetElement.name) { targetElement.name += suffix; }
  21. var ch = targetElement.childNodes;
  22. for(var i=0; i<ch.length; i++){
  23. renumberIt(ch[i], suffix);//drilldown with a recursive call.
  24. }
  25. }
This is a snippet from the middle of your html.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. ....
  2. <% for i = 0 to 6 %>
  3. <tbody id="day<%=i%>" class="day">
  4. <tr height="50px">
  5. <td blankMe="1" width="125px" style="border-bottom:1px solid #000000">
  6. <table>
  7. <tr>
  8. <td><a href="" alt="Add Another Stop" onclick="return addroute(<%=i%>);"><img src="images/plus.png" border="0" /></a></td>
  9. <td style="text-align: center; width: 100px;">
  10. ....
  11. ....
  12. <% end if %>
  13. </tr>
  14. </tbody>
  15. <% next %>
  16. </table>
  17. ....
Notes:
  1. Use <tbody></tbody> structure within table instead of <div></div>
  2. <a><img ...></a> instead of <input type="image" ...>
  3. Give cells whose content you want to be blanked in the new row a custom attribute of blankMe="1"
  4. Return false from addroute() and hence from its onclick call to suppress hyperlink action (or form submission or whatever).
  5. Note, embedded javascript in the cloned row will not run.
  6. 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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 18
Reputation: jsvanc is an unknown quantity at this point 
Solved Threads: 1
jsvanc jsvanc is offline Offline
Newbie Poster

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #3
Jun 27th, 2009
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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. onchange="showCols(<%=i%>);
  2.  

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
Attached Files
File Type: txt code.txt (15.5 KB, 1 views)
Hit any user to continue......
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 18
Reputation: jsvanc is an unknown quantity at this point 
Solved Threads: 1
jsvanc jsvanc is offline Offline
Newbie Poster

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #4
Jun 27th, 2009
One more thing, can I put a [-] next to the newly created rows in order to delete those rows just in case the user made a mistake and needs to remove an extra row?

Thank you
Hit any user to continue......
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #5
Jun 28th, 2009
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //--Find
  2. // day.tally = (day.tally) ? day.tally++ : 0;//Remember how many routes we have added
  3. //--replace with
  4. day.tally = (typeof day.tally == 'undefined') ? 0 : day.tally+1;//Remember how many routes we have added
  5. //--Find
  6. // if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = '&nbsp;'; }
  7. //--Replace with
  8. try{ if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = '&nbsp;'; } }//Necessary in FF
  9. catch(e){ ; }
  10. //--Find
  11. // day.appendChild(newRoute);
  12. //--add after
  13. resetRow(newRoute, n, suffix);
Add a new javascript function:
  1. function resetRow(row, n, suffix){
  2. var selects = row.getElementsByTagName('select');
  3. for(var i=0; i<selects.length; i++){
  4. selects[i].selectedIndex = 0;
  5. var baseName = selects[i].id.replace(n + suffix, '');
  6. switch(baseName){
  7. case ('leave'):
  8. case ('meeting'):
  9. case ('client'):
  10. try{
  11. var z=dhtmlXComboFromSelect(x + n + suffix,200);
  12. z.enableFilteringMode(true);
  13. z.setOptionWidth(450);
  14. }
  15. catch(e){ ; }
  16. break;
  17. default: //Do nothing
  18. }
  19. }
  20. var inputs = row.getElementsByTagName('input');
  21. for(var i=0; i<inputs.length; i++){
  22. switch(inputs[i].type.toLowerCase()){
  23. case 'checkbox':
  24. inputs[i].checked = 0;
  25. break;
  26. default: //Do nothing
  27. }
  28. }
  29. showCols(n + suffix);
  30. }
And in the HTML
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //--Find
  2. <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(<%=i%>);">
  3. //--Replace with
  4. <select id="type<%=i%>" name="type<%=i%>" onchange="showCols(this.getAttribute('id').replace('type', ''));">
  5. //--(This is messy but gets the job done)
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 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!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #6
Jun 28th, 2009
>> 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
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 18
Reputation: jsvanc is an unknown quantity at this point 
Solved Threads: 1
jsvanc jsvanc is offline Offline
Newbie Poster

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #7
Jun 28th, 2009
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 --
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <select name="client<%=i%>" id="client<%=i%>">
  2. <option value=""></option>
  3. <% For rowcounter = 0 To UBound(ClientListValues,2) %>
  4. <option value="<%=(ClientListValues(MyClient_Code,rowcounter))%>"><%=ClientListValues(MyClient_FName,rowcounter) & " - " & ClientListValues(MyClient_City,rowcounter) & ", " & ClientListValues(MyClient_State,rowcounter)%></option>
  5. <% Next %>
  6. </select>
  7. <script>
  8. var z=dhtmlXComboFromSelect("client<%=i%>",200);
  9. z.enableFilteringMode(true);
  10. z.setOptionWidth(450);
  11. </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......
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 18
Reputation: jsvanc is an unknown quantity at this point 
Solved Threads: 1
jsvanc jsvanc is offline Offline
Newbie Poster

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #8
Jun 28th, 2009
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.
Hit any user to continue......
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 811
Reputation: Airshow is on a distinguished road 
Solved Threads: 115
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #9
Jun 28th, 2009
JSV,

OK, here's the remove code.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //--Find
  2. if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = '&nbsp;'; }
  3. //--replace with
  4. if(newCells[i].getAttribute('blankMe') == "1"){ newCells[i].innerHTML = makeDeleteButton(n, suffix); }
  5.  
  6. //--Add new functions
  7. function deleteRoute(suffix){
  8. var id = "baseRoute" + suffix;
  9. var node = document.getElementById(id);
  10. if(!node) { return; }
  11. node.parentNode.removeChild(node);
  12. }
  13. function makeDeleteButton(n, suffix){
  14. return ['<a href="#" onclick="return deleteRoute(\'', (n + suffix), '\')"><img src="images/minus.png" border="0"></a>'].join('');
  15. }

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. //--Find
  2. <tr height="50px">
  3. //--replace with
  4. <tr id="baseRoute<%=i%>" height="50px">
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
Last edited by Airshow; Jun 28th, 2009 at 4:17 pm.
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 18
Reputation: jsvanc is an unknown quantity at this point 
Solved Threads: 1
jsvanc jsvanc is offline Offline
Newbie Poster

Re: Please Help!!! Problems Adding Row Dynamically using Javascript

 
0
  #10
Jun 29th, 2009
I finally figured out why the cloned rows won't populate the combobox. This code is the culprit:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script>
  2. var z=dhtmlXComboFromSelect("leave<%=i%>",200);
  3. z.enableFilteringMode(true);
  4. z.setOptionWidth(450);
  5. </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......
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC