TypeError (0x800a01a8): Object required: 'Document' - asp-classic

i have a classic asp page with inside the following vbscript
but it say that the Document object dose not exist why??
TypeError (0x800a01a8): Object required: 'Document'
the vbscript code:
<script language="vbscript" RUNAT="Server">
Function getDescriptionEstProc()
Dim CONNECTSTRING, QUALIFIER, QueryDescEstProc, dbConnect, res,output, param
CONNECTSTRING = Session("CONNECTSTRING")
QUALIFIER = Session("QUALIFIER")
param = PageParams1.UIDMeterHistory
QueryDescEstProc = "select e.description from meterhistory mh, meterread m, estimationprocess e where m.uidestproc = e.uidestproc and m.uidmeter = mh.uidmeter and mh.uidmeterhistory = '"& "0100001" &"'"
Set dbConnect = Server.CreateObject("ADODB.Connection")
Set rsWQType = Server.CreateObject("ADODB.Recordset")
dbConnect.Open CONNECTSTRING
rsWQType.Open QueryDescEstProc, dbConnect
res = ""
Do While Not rsWQType.EOF
res = res & rsWQType("description") & ","
Loop
Dim TheForm
Set TheForm = Document.forms("Form1")
TheForm.hiddenString.Value = res
Response.Write res & " - hello"
getDescriptionEstProc = res
End Function
</script>
(there is no aspx file)
the .asp file:
<form name="Form1" method="post" onkeypress="if (event.keyCode==13) {this.submit();event.returnValue=false;} else event.returnValue=true;">
<input class="lookup" type=hidden name="Id" value="<%=PageParams1.Id%>">
<input type=hidden name="SessionId" value="<%=PageParams1.SessionId%>">
<input type=hidden name="Command" value="">
<input type=hidden name="AccountID" value="<%=PageParams1.AccountID%>">
<input type=hidden name="UIDFACILITY" value="<%=PageParams1.UIDFACILITY%>">
<input type=hidden name="FACILITYID" value="<%=PageParams1.FACILITYID%>">
<input type=hidden name="METERID" value="<%=PageParams1.METERID%>">
<input type=hidden name="UIDMETER" value="<%=PageParams1.UIDMETER%>">
<input type=hidden name="UIDMeterHistory" value="<%=PageParams1.UIDMeterHistory%>">
<input type=hidden name="CustomerName" value="<%=PageParams1.CustomerName%>">
<input type=hidden name="CustomerId" value="<%=PageParams1.CustomerId%>">
<input type=hidden name="EntityParam" value="<%=PageParams1.EntityParam%>">
<input type=hidden name="SORT_BY" value="<%=PageParams1.SORT_BY%>">
<input type=hidden name="SORT_ORDER" value="<%=PageParams1.SORT_ORDER%>">
<input type=hidden name="Mode" value="<%=PageParams1.Mode%>">
<table class="SnapIn" cellpadding="0" cellspacing="0" border=0><tr class="ToolsTabs">
<td class="Title"><nobr><%=Proxy1.i18n.FM("MeterHistory")%></nobr></td>
<td class="ToolsLeft">
<b><%=Proxy1.i18n.FM("ID")%></b> <%=meterId %>
<%if (PageParams1.Mode == "ServicePoint") {%>
| <a href="../../ccs/MainWebPart.aspx?Mode=
<%=PageParams1.Mode%>&SessionId=<%=PageParams1.SessionId%>&Uid=
<%=Proxy1.Session.GetPropertyValue("SERVICEPOINT_UID")%>">
<%=Proxy1.i18n.FM("ServicePointSummary")%></a>
<% } else if (PageParams1.Mode == "MarketParticipant") { %>
| <a href="../../ccs/MainWebPart.aspx?Mode=
<%=PageParams1.Mode%>&SessionId=<%=PageParams1.SessionId%>&Uid=
<%=Proxy1.Session.GetPropertyValue("MARKETPARTICIPANT_UID")%>">
<%=Proxy1.i18n.FM("MarketParticipantSummary")%></a>
<% } %>
</td>
<td class="ToolsRight"><nobr>
<%if (PageParams1.AccountID) {%>
<b><%=Proxy1.i18n.FM("AccountID")%></b>
<a class="Link" onclick='window.navigate("../viewaccount/Meters.asp?Id=<%= escape(PageParams1.AccountID)%>&SessionId=<%=PageParams1.SessionId%>")'><u><%=PageParams1.AccountID %></u></a>
<%} if (PageParams1.CustomerId) {%>
<b><%=Proxy1.i18n.FM("CustomerID")%></b>
<a class='Link' onclick='navigate("../../ccs/MainWebPart.aspx?Id=<%=escape(PageParams1.CustomerId)%>&SessionId=<%=PageParams1.SessionId%>"+"&Mode=Customer")'>
<%=PageParams1.CustomerId%>
</a>
<%} if (PageParams1.UIDFACILITY) {%>
<b><%=Proxy1.i18n.FM("FacilityID")%></b>
<a class=Link onclick='navigate("../cust_facility/Basics.asp?UIDFACILITY=<%=PageParams1.UIDFACILITY%>&SessionId=<%=PageParams1.SessionId%>&X_ROWPERPAGE=50")'>
<%=PageParams1.FACILITYID%>
</a>
<%}%>
</nobr></td>
</tr><tr>
<td class="TabBox" colspan="3"><%= RenderTabs("MeterRead") %></td>
</tr><tr>
<td class="Body" colspan="3">
<% if (OperationError) ReportError(OperationError)%>
<%if (PageParams1.Command=='Edit') { %>
<table width=100%><tr><td class=LinkBox>
<%if (Proxy1.Allow("//ACCTMGT/ACCTCOMP/ACCTMET/#UPDATE")) {%>
<%=Proxy1.i18n.FM("Save")%> |
<%}%>
<%if (PageParams1.EntityParam && Proxy1.Allow("//ACCTMGT/ACCTCOMP/ACCTMET/#REMOVE") ) { %><%=Proxy1.i18n.FM("Delete")%> |<% } %>
<%=Proxy1.i18n.FM("Cancel")%>
</td></tr></table>
<%} else%>
<%=tMeterHistoryTable %>
<%if (PageParams1.Command != 'Edit') { %>
<table style="width: expression(Math.max(document.body.offsetWidth-55, 540))">
<tr>
<td align=left>
<%
if (Proxy1.Allow("//FACILITY/ADD"))
{
%>
<a href="javascript: Edit()" ><%=Proxy1.i18n.FM("Add")%></a>
<%
}
if (Proxy1.Allow("//FACILITY/REEST_ACTION/#REESTIMATE")) { %>
Ristima
<%
}
if (Proxy1.Allow("//FACILITY/REEST_ACTION_2")) { %>
Ristima lettura conferimento
<% }
if (Proxy1.Allow("//FACILITY/REEST_ACTION/#DISCHARGE")) { %>
Scarta
<% } %>
</td>
<!--Indicazione righe e pagina-->
<td align=right>
<%= Paginator_b(PageParams1.ROWPERPAGE, PageParams1.PAGENUMBER) %>
</td>
</tr>
</table>
<%
}
%>
<div class="mAppScroll" style="height:100% width:100%"><% =tTable %></div>
<tr>
<td>
<!--Cannata Alberto - modifica del 09/10/2006: aggiorniamo i campi LSUSER e LSTIME della METERHISTORY.-->
<input type="hidden" name = "OLD_STATUS" value = "<%=oldstatus_str%>">
<input type="hidden" name = "X_LSUSER" value = "<%=username_web.toUpperCase()%>">
<input type="hidden" name = "X_LSTIME" value = "<%=data_modifica%>">
</td>
</tr>
</td>
</tr>
</table><!-- /SnapIn -->
<input type="hidden" id="hiddString" name="hiddenString" value="">
<%
getDescriptionEstProc();
%>
<SCRIPT language="javascript">
appendColumn();
</SCRIPT>

Document.Forms is not used in server-side ASP, it's used in client-side code such as Javascript and VBScript. If you are trying to post data with your form, look into using Request["fieldname"] to get the values you need.
It looks like you're just trying to set the value of the hidden field?
Since the function returns the value you want (res), just do this:
<input type="hidden" id="hiddString" name="hiddenString" value="<%=getDescriptionEstProc()%>">
Hope this helps.
Good luck.

Related

How to add total from a search form

I like to query based on some fields to generate a report: Date range, Department, Student with date range. I have the form to work on searching....
However, I need to calculate totals for each of these fields from a report.
For example: if I search for students and the search results are:
Department Date Range Student Cost
DeptA 1/1/2012-12/31/2012 StuA $100
DeptA 1/1/2012-12/31/2012 StuB $50
DeptA 1/1/2012-12/31/2012 StuC $50
How can I calculate the total of cost automatically online (= $200)?
Thanks.
Here is my code:
<%
Path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(Path, 1) <> "\" And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.open strCon
SelectStmt = "Select * From view_costs Where "
WhereClause = ""
WhereBetweenClause = "BETWEEN"
If Request("qryDepartment") <> "All Departments" Then
qryDepartment = replace(request("qryDepartment"),"'","''")
WhereClause = WhereClause & "Department = '" & qryDepartment & "' AND "
End If
If Request("qryStudents") <> "All Students" Then
WhereClause = WhereClause & "Name = '" & Request("qryStudents") & "' AND "
End If
sStartDate = Request("StartDate")
sEndDate = Request("EndDate")
If IsDate(sStartDate) And IsDate(sEndDate) Then
WhereClause = WhereClause & "(StartDate >= '" & sStartDate & "' AND EndDate <= '" & sEndDate & "') "
End If
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.open strCon
pstart = trim(request.form("pstart"))
pfinish = trim(request.form("pfinish"))
Set getDepartment = Server.CreateObject("ADODB.Recordset")
getDepartment.Open "Select Department from view_costs order by Department;",adoCon
Set getname = Server.CreateObject("ADODB.Recordset")
getname.Open "Select Name from view_costs order by Name;",adoCon
%>
<html>
<head>
<title>The Resport</title>
</head>
<body>
<table width="770" align="center">
<tr>
<td colspan="4" class="n"><span id="h3">Search Menu</span></td>
</tr>
<form method=Department action="Search.asp" name="Search">
<tr>
<td>
<% if not getDepartment.eof then %>
<select name="qryDepartment" size="1" title="Select a Department Name" style="width:200;background-color=#F5D0A9;">
<option selected>All Departments</option>
<% do until getDepartment.eof %>
<option><%= getDepartment("Department") %></option>
<% getDepartment.MoveNext
loop %>
</select>
<% end if %>
</td>
<td>
<% if not getname.eof then %>
<select name="qryStudents" size="1" title="Select a Student Name" style="width:200;background-color=#F5D0A9;">
<option selected>All Students</option>
<% do until getname.eof %>
<option><%= getname("Name") %></option>
<% getname.MoveNext
loop %>
</select>
<% end if %>
</td>
<%
%>
<td><span id="b"> Start:</span> <input name="StartDate" type="text" size="15" maxlength="12" value="<%=sStartDate%>">
<img src="calendar.gif" alt="calendar"></td>
<td><span id="b"> End:</span> <input name="EndDate" type="text" size="15" maxlength="12" value="<%=sEndDate%>">
<img src="calendar.gif" alt="calendar"></td>
</tr>
<tr class="search-bg">
<td colspan="6">
<input type="button" name="Submit" value="Search" onClick="if (isDate()) document.Search.submit();">
</tr></table>
<% If oRs.RecordCount = 0 Then %>
<p></p>
<% Else %>
<table width="960" align="center">
<form method="Department">
<tr bgcolor="#FE9A2E" height="25">
<td class="a"> Department Name</td>
<td class="a"> Student</td>
<td class="a"> Start</td>
<td class="a"> End</td>
<td class="a"> Cost</td>
</tr>
<tr>
<td><%=oRs("Department")%> </td>
<td><%=oRs("Name")%> </td>
<td><%=FormatDateTime(Month(oRs("StartDate")) & "/" & Day(oRs("StartDate")) & "/" & Year(oRs("StartDate")))%> </td>
<td><%=FormatDateTime(Month(oRs("EndDate")) & "/" & Day(oRs("EndDate")) & "/" & Year(oRs("EndDate")))%> </td>
<td <%=sRowStyle%>>$<%=oRs("Cost")%> </td>
</tr>
<% oRs.MoveNext %>
<% WEND %>
</table>
</td>
</tr>
</table>
<% oRs.close
set oRs = nothing
set adoCon = nothing
%>
Why not specify the fields in your SQL (instead of "SELECT * ..."), then add up the values via variables in the loop and output them in a new table row after the loop?
Or you could use SQLs SUM() function to query those values.

asp.net with underscore templatesettings

I suppose there are people who encountered underscore problem, so I found something here:
Using Underscore.js with ASP.NET
and the solution was to add:
_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g, // print value: {{ value_name }}
evaluate : /\{%([\s\S]+?)%\}/g, // excute code: {% code_to_execute %}
escape : /\{%-([\s\S]+?)%\}/g}; // excape HTML: {%- <script> %} prints <script>
to underscore.js
so I opened underscore.js and found the _.templateSettings section, and replaced with the above solution, still with no luck.
Is there anywhere that I'm missing? here's my code looks like:
<table class="table">
<thead>
<tr>
<th></th>
<th>#</th>
<th>Keyword</th>
<th>Corresponding Field</th>
<th>Add</th>
</tr>
</thead>
<tbody>
<% _.each(keywords, function(keyword, key, list) { %>
<tr>
<td><label class="checkbox"><input type="checkbox" /></label></td>
<td><%= key + 1 %></td>
<td><input name="keywords[<%= key %>][keyword]" class="input-medium keyword-name" type="text" value="<%= keyword.name %>" /></td>
<td>
<select class="keyword-field">
<% _.each(fields, function(field, key, list) { %>
<option name="keywords[<%= key %>][field]" value="<%= field.id %>" <% if (keyword.fieldId == field.id) { %>selected<% } %>><%= field.name %></option>
<% }); %>
</select>
</td>
<td class="align-right">Define</td>
</tr>
<% }); %>
</tbody>
</table>
so this is what I end up doing:
<script type="text/javascript">
$(document).ready(function ()
{
_.templateSettings = {
interpolate: /\<\#\=(.+?)\#\>/g,
evaluate: /\<\#(.+?)\#\>/g
};
});
</script>
above code inside html head
and change to <# ... #>
so this is what my code ends up:
<tbody>
<# _.each(keywords, function(keyword, key, list) { #>
<tr>
<td><label class="checkbox"><input type="checkbox" /></label></td>
<td><#= key + 1 #></td>
<td><input name="keywords[<#= key #>][keyword]" class="input-medium keyword-name" type="text" value="<#= keyword.name #>" /></td>
<td>
<select class="keyword-field">
<# _.each(fields, function(field, key, list) { #>
<option name="keywords[<#= key #>][field]" value="<#= field.id #>" <# if (keyword.fieldId == field.id) { #>selected<# } #>><#= field.name #></option>
<# }); #>
</select>
</td>
<td class="align-right">Define</td>
</tr>
<# }); #>
</tbody>

Uploading a file and submitting a form at the same time, using vb

so I have a slight issue with doing 2 things on a web page. I'm using a to upload a file to my web server, at the same time I have other used to get data from the user (first name, last name ect) The form is runat=server, the button that is supposed to upload the file (after some preliminary checking that the file is ok, and that the forms fields are filled out properly) is also runat server, with a onserver click.
The main issue is that, when I give the form a "get" method, I can get the desired result of having all my data in the url where I want it, but then I can't upload a file. While if I remove that tag, I can upload a file, but then I get no data in my url.
(Relevant code)
<script language="VB" runat="server">
Dim str As String
Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs)
'Dim submitFunction As String = "<script type='text/javascript'> function submitform() { document.myform.submit();}" & "</" & "script>"
Session("firstTime") = 4
Session("errCheck") = 1
If InputF.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If
If Not (InputF.PostedFile Is Nothing) Then
Try
If Session("firstTime") <> 1 Then
If Request.QueryString("fName") = "" Then
str += "Please Enter your first name <br/>"
Session("errCheck") += 1
End If
If Request.QueryString("lName") = "" Then
str += "Please Enter your last name <br />"
Session("errCheck") += 1
End If
If Request.QueryString("addr1") = "" Then
str += "Please Enter your address <br />"
Session("errCheck") += 1
End If
If Request.QueryString("city") = "" Then
str += "Please Enter a city name <br />"
Session("errCheck") += 1
End If
If Len(Request.QueryString("prov")) <> 2 Then
str += "Please Enter a 2 character province <br />"
Session("errCheck") += 1
End If
If Len(Request.QueryString("pCode")) <> 6 Then
str += "Please Enter a valid postal code <br />"
Session("errCheck") += 1
End If
If Request.QueryString("hPhone") = "" Then
str += "Please Enter your home phone <br />"
Session("errCheck") += 1
ElseIf Len(Request.QueryString("hPhone")) <> 10 Then
str += "Please enter a 10 digit number for your home phone <br />"
Session("errCheck") += 1
End If
End If
If Session("errCheck") = 1 Then
InputF.PostedFile.SaveAs(("FILE PATH TO MY SERVER" & Request.QueryString("compName") & " - " & Request.QueryString("fName") & ", " & Request.QueryString("lName") & InputF.Value))
'Response.Redirect("default.aspx?fName=" & Request.QueryString("fName"))
End If
Catch exc As Exception
str += "Error Saving File"
Span1.InnerHtml = "Error saving file"
Session("errCheck") += 1
End Try
End If
End Sub 'Button1_Click
</script>
<form name="myform" id="myform" method="get" runat="server" enctype="multipart/form-data">
<table>
<h2><% If Session("errCheck") <> 1 Then
Response.Write(Str)
End If%></h2>
<tr>
<td align="right"><label>Resume/Documents</label></td>
<td><input type="file" runat="server" id="InputF" name="InputF" onchange="handleFiles(this.files)" /><input type="button" id="adder" value="add another document" onclick="addInput('dynamicInput');" /></td>
<div id="dynamicInput">
</div>
</tr>
<tr>
<td>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />
</td>
</tr>
<input type="hidden" id="Hidden13" name="compName" value="<% response.Write(request.QueryString("compName")) %>" />
<input type="hidden" id="posCode" name="posCode" value="<% response.Write(request.QueryString("posCode"))%>" />
<input type="hidden" id="reqNum" name="reqNum" value="<% response.Write(request.QueryString("reqNum")) %>" />
<input type="hidden" id="company" name="company" value="<% response.Write(request.QueryString("company"))%>" />
<input type="hidden" id="division" name="division" value="<% response.Write(request.QueryString("division")) %>" />
<input type="hidden" id="department" name="department" value="<% response.Write(request.QueryString("department"))%>" />
<tr>
<td align="right">First name<span style="color:Red;">*</span>:</td>
<td><input type='text' name='fName' id='fName' size='50' maxlength="50"value="<% Response.Write(Request.QueryString("fName"))%>" /></td>
</tr>
<tr>
<td align="right"><label>Last name </label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='lName' id='lName' size='50' maxlength="50" value="<% response.Write(request.QueryString("lName"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Initial</label>:</td>
<td><input type='text' name='init' id='init' size='2' maxlength="2" value="<% response.Write(request.QueryString("init"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Email</label>:</td>
<td><input type='text' name='email' id='email' size='50' maxlength="50" value="<% response.Write(request.QueryString("email"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Address 1</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='addr1' id='addr1' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr1"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Address 2</label>:</td>
<td><input type='text' name='addr2' id='addr2' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr2"))%>"/></td>
</tr>
<tr>
<td align="right"><label>City</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='city' id='city' size='25' maxlength="25" value="<% response.Write(request.QueryString("city"))%>"/></td>
</tr>
<br />
<tr>
<td align="right"><label>Province</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='prov' id='prov' size='2' maxlength="2" value="<% response.Write(request.QueryString("prov"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Country</label>:</td>
<td><input type='text' name='count' id='count' size='25' maxlength="25" value="<% response.Write(request.QueryString("count"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Postal code</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='pCode' id='pCode' size='25' maxlength="25" value="<% response.Write(request.QueryString("pCode"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Home Phone</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='hPhone' id='hPhone' size='15' maxlength="15" value="<% response.Write(request.QueryString("hPhone"))%>"/></td>
<p>Format for phone numbers: Areacode, phone number, no spaces, no dashes ie: 2041231234</P>
</tr>
<tr>
<td align="right"><label>Work Phone</label>:</td>
<td><input type='text' name='wPhone' id='wPhone' size='25' maxlength="25" value="<% response.Write(request.QueryString("wPhone"))%>"/></td>
</tr>
</table>
<input type=button
id="Button1"
value="Submit Application"
OnServerClick="Button1_Click"
runat="server" />
</form>
I was close to getting this myself. On form submit, I do all the validation for the other files, then if all checks out, I submit the form to a different page(with other non-relevant code).
Basically the code I posted is good, I was just missing a few things for when it's submitted
In short:
'if there are no errors with the user feilds
If Session("errCheck") = 1 Then
Try
If Not (System.IO.Path.GetFileName(InputF.PostedFile.FileName.ToString()) Is Nothing) Then
Try
InputF.PostedFile.SaveAs(("somepath:\somepath\somepath\somepath\" & Trim(Request.Form("compName")) & " - " & Request.Form("lName") & ", " & Request.Form("fName") & "-" & System.IO.Path.GetFileName(InputF.PostedFile.FileName.ToString())))
Catch ex As Exception
Session("errCheck") += 1
str += "Error Saving File" & ex.Message
End Try
If Session("errCheck") = 1 Then
Response.Redirect("final2.aspx?fName=" & Request.Form("fName") & "&lName=" & Request.Form("lName") & "&compName=" & Trim(Request.Form("compName")) &
"&posCode=" & Request.Form("posCode") & "&reqNum=" & Request.Form("reqNum") & "&company=" & Request.Form("company") &
"&division=" & Request.Form("division") & "&department=" & Request.Form("department") & "&init=" & Request.Form("init") &
"&email=" & Request.Form("email") & "&addr1=" & Trim(Request.Form("addr1")) & "&addr2=" & Request.Form("addr2") &
"&city=" & Request.Form("city") & "&prov=" & Request.Form("prov") & "&count=" & Request.Form("count") &
"&pCode=" & Request.Form("pCode") & "&hPhone=" & Request.Form("hPhone") & "&wPhone=" & Request.Form("wPhone"))
End If
Hopefully that makes sense to anyone looking at my question and now my answer.

Invoicing in classic Asp + Ajax

I need to a form for invoicing,
Please help me to have some Idea how to insert all the data at once into invoice table.
I am using text box to get all details for items .
here is the code for get details of items from table.
enter code here<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))%>
<tr>
<td><input name="dipatchid" type="text" id="dipatchid" value="<%=(Recordset1.Fields.Item("dispatchid").Value)%>" size="5" /></td>
<td><input name="dispatchdate" type="text" id="dispatchdate" value="<%=(Recordset1.Fields.Item("dis_date").Value)%>" /></td>
<td><input type="hidden" name="custid_" id="custid_" />
<input name="From_" type="text" id="From_" value="<%=(Recordset1.Fields.Item("from_").Value)%>" /></td>
<td><input name="to_" type="text" id="to_" value="<%=(Recordset1.Fields.Item("To_").Value)%>" /></td>
<td><input name="hrs" type="text" id="hrs" value="<%=(Recordset1.Fields.Item("total_hrs").Value)%>" size="5" /></td>
<td><input name="rate_" type="text" id="rate_" size="8" /></td>
<td><input name="totalamt" type="text" id="totalamt" size="10" /></td>
<td><img src="imgs/error_icon.png" width="16" height="16" alt="Remove" /></td> </tr>
<% Repeat1__index=Repeat1__index+1 Repeat1__numRows=Repeat1__numRows-1 Recordset1.MoveNext() Wend %>
To accomplish this, you will need to keep track of two things:
the number of rows that are going to be inserted
the data of each row
Tricks to do this, is simple. While you display your data, you increment a variable with the number of loops.
<%
iNumberOfRecords = 0
Do Until Recordset1.EOF
%>
<tr>
<td>
<input name="dipatchid" type="text" id="..." value="<%=Recordset1("dispatchid")%>" />
</td>
...
</tr>
<%
iNumberOfRecords = iNumberOfRecords + 1
Recordset1.MoveNext
loop
Recordset1.Close
%>
Before you close your <form> tag, you put that in a hidden field.
<input type="hidden" name="iNumberOfRecords" value="<%=iNumberOfRecords%>" />
Next, on the page where you submit to, you loop iNumberOfRecords times to insert all the rows.
<%
for i = 1 to CInt(Request.Form("iNumberOfRecords"))
idOfRecord = GetFormValue("dipatchid", i)
otherField = GetFormValue("otherField", i)
SQL = "INSERT INTO tblInvoices(dispatchid, otherfield) VALUES ( " & idOfRecord & ", " & otherfield & " )"
Connectionobject.Execute(SQL)
next
Function GetFormValue(sFormname, iIndex)
If Request.Form(sFormname).Count >= iIndex And iIndex > 0 Then
GetFormValue = Request.Form(sFormname)(iIndex)
Else
GetFormValue = ""
End If
End Function
%>
The (i) fetches the right Request.Form("...") item for you.

One submit to make a Query in HTML-ASP page and a normal submit

I want to have a Query been executed when I press the button, then follow filling other filds. Everything works fine if I only execute the Query, but I put the other steps then the Query is not executed.
I will really appreciate any kind of help
Here are the codes :
<form action="" method="POST">
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/TextDB.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT Country FROM TheCountries ORDER BY Country"
rs.Open sql,conn
country=request.form("country")
%>
Select the Country <select name="country">
<% do until rs.EOF
response.write("<option")
if rs.fields("country")=country then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("Country"))
rs.MoveNext
loop
rs.Close
set rs=Nothing %>
</select>
<input type="submit" value="Show Countries">
<%
if country<>"" then
sql="SELECT Country, City, Cost FROM TheCities WHERE country='" & country & "' Order by City"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn
city=request.form("city")
cost=request.form("cost")
%>
<br>
Select The City <select name="city">,
<% do until rs.EOF
response.write("<option")
if rs.fields("city")=city then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("City") & " " & rs.fields("Codigo"))
rs.MoveNext
loop
rs.Close
conn.Close
set rs=Nothing
set conn=Nothing%>
</select>
<% end if %>
</form>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="80%"><tr><td>
<form action="_gdForm/webformmailer.asp" method="POST" target="_top" class="formmargin">
<input type="hidden" name="recipient" value="ramon_batista#hotmail.com">
<input type="hidden" name="subject" value="WebSite Contact">
<input type="hidden" name="redirect" value="/thanksespanol.htm">
<input type="hidden" name="required" value="your_name,phone,country,city">
<input type="hidden" name="sort" value="your_name,phone,country,city">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr><td>
Name:<br>
</td></tr><tr><td>
<input type="text" name="your_name" size="40" class="shadeform"><br>
</td></tr><tr><td>
</td></tr><tr><td>
<script language="JavaScript" type="text/javascript" src="myscrip.js"></script>
<script language="JavaScript" type="text/javascript">
</script>
#user633228: You've got two forms. The first query isn't part of the second form which is why it isn't submitting along with it. What you can perhaps do is only display the first form and then only show the second one with
If country <> "" Then
' Show other form
End If
Add another <input type="hidden" name="country" value="<%=country %>"> to the second form so country's value will be sent along.

Resources