Do not use on any
shared computer
August 30, 2008 04:30am pdt
 
[x]
Attachment Details

Automatically add name to input tag

Tags: Javascript, ASP, HTML, Firefox 2, IE 7
Hello Experts.  This is a very urgent question.  I am currently developing a classic ASP-based page that pulls data off an AS400 system (pulling anywhere from 100-300 records) using an ODBC connection and then exports the data into an Excel spreadsheet.  The data is displayed perfectly on the web site, but I'm having issues with the export.  The ASP/HTML code is running through a loop, and I'm having problems with input fields having the same name.  This causes a lot of problems when exporting to Excel.  I've tried mixing and matching different recordsets in the code, so that the items could be displayed properly.  But there are still some strange issues with the exported file.

What I'm looking for is a way to automatically name the input fields (like number1, number2, number3, quan1, quan2, quan3, etc), rather than using the "rs.fields("name")" tag inside the name.  It would be so much easier for me to handle and the export should be displayed fine then.  The naming of the fields may look a tad strange, but it's the best I've gotten so far when exporting.  I'd really like to get rid of those recordsets as the names.  Below is a screenshot of the site content and the primary Javascript and ASP code to give you a better idea towards what I'm after.  This project is still a work in progress, so ignore any other errors that you may find...unless it will help me with the input naming.  ;)

Thank you for any help, it's greatly appreciated!

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
Javascript (checkbox enables/disables form fields):
 
<script type="text/javascript"> 
function toggle(){ 
var args=toggle.arguments, els=typeof args[0]=='object'? args[0].elements : document.forms[args[0]].elements; 
for (var i = els.length-1; i > -1; --i) 
for (var j = args.length-2; j > 0; --j) 
if(els[i].name==args[j]) 
els[i].disabled=args[args.length-1]; 
} 
toggle.init=function(){ 
for (var f=document.forms, i = f.length-1; i > -1; --i) 
for (var e=f[i].elements, j = e.length-1; j > -1; --j) 
if(e[j].className&&/disabled/.test(e[j].className)) 
e[j].disabled=true; 
}; 
</script> 
 
------------------------------------------------------------
 
ASP (index.asp):
 
  <% 
  Set cmd = Server.CreateObject("ADODB.Command") 
  Set rs = Server.CreateObject("ADODB.Recordset") 
  Set rs2 = Server.CreateObject("ADODB.Recordset") 
  Set Connection = Server.CreateObject("ADODB.Connection") 
        
  Connection.Open "User ID=user;Password=pass;Data Source=dsn;" 
  
SQLSTMT = "SELECT KPKIT, KPSEQ, KPCOM, DESCP, DSCPS, LSTPC, KPQTY from demo where kit = '103'" 
SQL = "SELECT SUM(LSTPC) AS Total FROM demo where kit = '103'" 
 
 Set RS = Connection.Execute(SQLSTMT) 
 
 Response.Write("<table>") 
 
 Do While Not RS.EOF 
 
  if background = ""  or Background = "#F7F7F7" then 
     background = "#FFFFFF" 
  else 
     background = "#F7F7F7" 
  end if   
  %> 
  
  <form id="form1" name="form1" method="post" action="index1.asp"> 
  
 
  <tr id="row"> 
 
  
  <td width=25px> 
  <input type="checkbox" name="check" onclick="toggle(this.form, '<%=rs.fields("KPSEQ")%>', '<%=rs.fields("DESCP")%>', '<%=rs.fields("KPCOM")%>', !this.checked)" /> 
  </td> 
  
  <td width=80px> 
  <input type="text" name="<%=rs.fields("KPSEQ")%>" value="<%=(RS.Fields("KPCOM"))%>" size="13" maxlength="13"> 
  </td> 
  
  <% 
  Response.Write("<td width=500px>") 
  Response.Write(RS.Fields("DESCP")) 
  Response.Write(RS.Fields("DSCPS")) 
  Response.Write("</td>")   
  %> 
  
  <td width=66px> 
  <input type="text" name="<%=rs.fields("DESCP")%>" value="1" size="4" maxlength="4"> 
  </td> 
 
  <td width=66px> 
  <input type="text" name="<%=rs.fields("KPCOM")%>" value="$<%=(RS.Fields("LSTPC"))%>.00" size="10" maxlength="10"> 
  </td> 
  
</tr> 
    
   <% 
   rs.MoveNext 
   loop 
   rs.Close 
 
Response.Write("</table>") 
 
Response.Write("<p>") 
Response.Write("</p>") 
 
 Set RS2 = Connection.Execute(SQL) 
    If Not RS2.EOF THEN 
      Response.Write("Total Cost: &nbsp;$") 
          Response.Write RS2("Total") 
END IF 
%> 
 
<p> </p> 
<input type="submit" name="Submit2" value="Export&nbsp;to&nbsp;Excel" /> 
&nbsp;&nbsp;&nbsp; 
<input type=reset name=Submit3 value=Reset&nbsp;Values /> 
 
</form> 
<script type="text/javascript"> 
toggle.init(); 
</script> 
 
------------------------------------------------------------
 
ASP (index1.asp - Export to Excel):
 
<%@LANGUAGE="VBSCRIPT" %> 
<% 
   Response.Buffer = TRUE 
   Response.ContentType = "application/vnd.ms-excel" 
%> 
 
<TABLE WIDTH=920 BORDER=1 CELLPADDING=5 CELLSPACING=5 bordercolor="#000000"> 
<TR> 
   <TD width="120" bgcolor="#f16122"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Part Number</font></strong></TD> 
   <TD width="524" bgcolor="#f16122"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Description</font></strong></TD> 
   <TD width="89" bgcolor="#f16122"><div align="right"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Quantity</strong></font></div></TD> 
   <TD width="115" bgcolor="#f16122"><div align="right"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Price</strong></font></div></TD> 
</TR> 
 
<% CurrentItem = 0 
do while not rs.EOF %> 
 
<TR> 
<%CurrentItem = CurrentItem +1%> 
   <TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=request.form(cstr(rs.fields("KPSEQ")))%></font></TD> 
   <TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=rs("DESCP")%><%=rs("DSCPS")%></font></TD>   
   <TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=request.form(cstr(rs.fields("DESCP")))%></font></TD>     
   <TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=request.form(cstr(rs.fields("KPCOM")))%></font></TD> 
</TR> 
 
<% 
rs.MoveNext 
   loop 
   rs.Close 
%> 
 
 
<p></p> 
<tr> 
<td bgcolor="#f16122"><font size="2">&nbsp;</font></td> 
<td bgcolor="#f16122"><font size="2">&nbsp;</font></td> 
<td bgcolor="#f16122"><div align="right"><font size="2"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Total Cost:</font></strong></font></div></td> 
 
<td bgcolor="#f16122"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">=sum(d10:d134)</font></strong></td> 
</tr> 
</TABLE>
Attachments:
 
Screenshot displaying database data.
Screenshot displaying database data.
 
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Web Development
Question Asked By: hx3
Solution Provided By: angelIII
Participating Experts: 1
Solution Grade: A
Views: 26
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by angelIII

Rank: Sage

Accepted Solution by angelIII:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by hx3
Author Comment by hx3:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628