Advertisement

05.03.2008 at 11:07AM PDT, ID: 23374065
[x]
Attachment Details

Automatically add name to input tag

Asked by hx3 in Active Server Pages (ASP), JavaScript

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!

Start Free Trial
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.
 
 
 
[+][-]05.03.2008 at 11:11AM PDT, ID: 21493223

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), JavaScript
Tags: Javascript, ASP, HTML, Firefox 2, IE 7
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.03.2008 at 01:29PM PDT, ID: 21493598

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628