Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pulling a value from a text box

Status
Not open for further replies.

andyfresh

Technical User
Oct 4, 2005
33
0
0
GB
Hi

Im currently try to run this scrippt where by when the user clicks the delete button the function deleteline() function runs which will display the line id on the page. However I cant seem to get the lineid value to be sent to the broswer.

Any ideas?

Andy

Code:
<SCRIPT id=DebugDirectives runat=server language=javascript>
// Set these to true to enable debugging or tracing
@set @debug=false
@set @trace=false
</SCRIPT>
<script language="JavaScript" type="text/javascript">
<!--
SetPageTitle('View Order')
//-->
</script>
<%
if len(request("recID")) > 0 then
	strRecordid = request("recID")
else
	strRecordid = request("OrderNo")
end if

Response.Write "<script language=""JavaScript"" type=""text/javascript"">" & VbCr
Response.Write "<!--// "& VbCr
Response.Write "function ConfirmChoice()"& VbCr
Response.Write "{ "& VbCr
Response.Write "answer = confirm(""Are you sure you want to delete this order?"")"& VbCr
Response.Write "if (answer !=""0"") "& VbCr
Response.Write "{ "& VbCr

Response.Write "window.location = 'showorder.asp?switch=d&OrderID=" & strRecordid & "&recID=" & strRecordid & "'"& VbCr
Response.Write "} "& VbCr
Response.Write "}"& VbCr
Response.Write "//-->"& VbCr
Response.Write "</script>"& VbCr

Response.Write "<script language=""JavaScript"" type=""text/javascript"">" & VbCr
Response.Write "<!--// "& VbCr
Response.Write "function DeleteLine()"& VbCr
Response.Write "{ "& VbCr
Response.Write "answer = confirm(""Are you sure you want to delete this line?"")"& VbCr
Response.Write "if (answer !=""0"") "& VbCr
Response.Write "{ "& VbCr
Response.Write "window.location = 'showorder.asp?switch=dl&OrderID=" & strRecordid & "&recID=" & strRecordid & "&lID=" & strid & "'"& VbCr
Response.Write "} "& VbCr
Response.Write "}"& VbCr
Response.Write "//-->"& VbCr
Response.Write "</script>"& VbCr

Dim lngOrderID
Dim objRs
Dim objConn

'START OF SWITCH - DELETE ORDER
if Request("switch") = "d" then
strConn = Application("conLIVEoledb_ConnectionString")
'strConn = Application("conDevTest_ConnectionString")
Set objConn = Server.CreateObject ("adodb.connection")
Set cmd = Server.CreateObject ("adodb.command")
Set objRs = Server.CreateObject ("adodb.recordset")
cmd.CommandTimeout = 600
objConn.Open strConn
Set cmd.ActiveConnection = objConn
objRs.CursorType = adOpenForwardOnly
objRs.LockType = adLockReadOnly
objRs.CursorLocation = adUseServer


cmd.CommandText = "deleteorder"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("OrderID", adVarChar, adParamInput, 20)
cmd("OrderID") = CStr(strRecordid)
cmd.Execute

Set objRs = nothing
Set objConn = nothing
'DELETE LINE ITEM
elseif Request ("Switch") = "dl" then

if  Request("strid") = "" then
strid = Request("id")
'strid = "noid"
end if

Response.Write"Line Item Deleted orderid=" & strRecordid & " and line No =" & strid & ""
end if
'END OF SWITCH

Response.Write "<BR><BR><FORM name=thisForm1 id=thisForm1 action=""showorder.asp?switch=d&OrderID=" & strRecordid & "&lID=" & strid & "&recID="& strRecordid &""" Method=POST><table width=""90%"" border=1 FRAME=Box RULES=none BORDERCOLOR=#666699 cellpadding=3 cellspacing=0 align=center style=""border-color:#666699;border-width:1px;border-style:solid;border-collapse:collapse;"">"
strLogonUser = TRIM(Request.ServerVariables("REMOTE_HOST"))
If  strLogonUser = "192.168.1.200" OR strLogonUser = "62.254.128.4" then
	CanConfirm = True
Else
	CanConfirm = False
End If

strConn = Application("conLIVEoledb_ConnectionString")

Set objConn = Server.CreateObject ("adodb.connection")
objConn.Open strConn
Set objRs = Server.CreateObject ("adodb.recordset")
objRs.CursorType = adOpenForwardOnly
objRs.LockType = adLockReadOnly
objRs.CursorLocation = adUseServer
'****************************************************************************************
SQL= **SQL SCRIPT HERE**
'****************************************************************************************
Set objRs = objConn.Execute(SQL)
if objRS.bof and objRS.eof then
Response.Write"Order Deleted"
else


lngOrderID = CLng(objRs("OrderNo"))
Response.Write "<input type=hidden id=OrderNo name=OrderNo value="& cstr(lngOrderID) & ">"& VbCr
Response.Write "<input type=hidden id=recID name=recID value=" & Request("recID") & ">"& VbCr
Response.Write "<TR BGCOLOR=#666699><TD colspan=6><B><FONT COLOR=#ffffff>Order No " & objRs("OrderNo") & " &nbsp;: &nbsp;" & objRs("Outlet") & " &nbsp;: &nbsp;Supplied by " & objRs("Wholesaler") & "</FONT></B></TD><TD></TD><TD></TD></TR>"
Response.Write "<TR BGCOLOR=#b0c4de><TD>Wholesaler</TD>"
Response.Write "<TD>Description</TD>"
Response.Write "<TD align=left colspan=2>Qty Ordered</TD>"
Response.Write "<TD align=right>Price</TD>"
Response.Write "<TD align=center>Qty Dispatched</TD>"
Response.Write "<TD align=right>Line Total</TD>"
Response.Write "<TD align=right></TD></TR>"
If IsNull(objRs("VAT")) then
	strVAT = "0.00"
	strNetTotal = convertCurrency(CStr(objRs("Total")))
else
	strVAT = convertCurrency(CStr(objRs("VAT")))
	strNetTotal = convertCurrency(CStr(objRs("Total")+ objRs("VAT")))
End If
strGrossTotal = convertCurrency(objRs("Total"))

If objRs("Dispatched") = 1 then
	Dispatched = True
else
	Dispatched = False
End If
count = 1
While Not objRs.EOF
if (count mod 2) = 1 then
	Response.Write "<TR BGCOLOR=#ffffff>" & VbCr
Else
	Response.Write "<TR BGCOLOR=#b0c4de>" & VbCr
End If
count = count + 1
If objRs("Split") = 0 then
	If Trim(objRs("BulkName")) = "&nbsp;&nbsp;" then
		strUnit = objRs("SplitName")
	Else
		strUnit = objRs("BulkName")
	End If
Else
	strUnit = objRs("SplitName")
End If
If IsNull(objRs("LineTotal")) then
	strLineTotal = "0.00"
else
	strLineTotal = convertCurrency(CStr(objRs("LineTotal")))
End If

Response.Write "<TD>" & objRs("Wholesaler") & "</TD><TD> " & objRs("DescriptionName") & " " & objRs("DetailName") & " " & objRs("OriginName") & "</TD>" & VbCr
Response.Write "<TD align=right> " & objRs("Quantity") & "x</TD>" & VbCr
Response.Write "<TD align=left> " & strUnit & "</TD>" & VbCr
Response.Write "<TD align=right> " & convertCurrency(CStr(objRs("Price"))) & "</TD>" & VbCr
Response.Write "<TD align=center> " & objRs("QuantityDispatched") & "</TD>" & VbCr
Response.Write "<TD align=right> " & strLineTotal & "</TD>" & VbCr
Response.Write "<TD colspan=6 align=right>" & VbCr
Response.Write "<input type=text id=lineid name=lineid value=" & objRs("id") & ">" & VbCr


Response.Write "<Input Type=Button onclick=DeleteLine(); return false; value=""Delete"" id=Button1 name=Button1></TD></TR>"

objRs.moveNext

Wend
Response.Write "<TR height=1 bgcolor=#666699><TD colspan=6></TD><TD></TD><TD></TD></TR>"
Response.Write "<TR><TD></TD><TD></TD><TD align=right colspan=5> Gross Total </TD><TD align=right>" & strGrossTotal & "</TD><TD></TD></TR>" & VbCr
Response.Write "<TR><TD></TD><TD></TD><TD align=right colspan=5> VAT </TD><TD align=right>" & strVAT & "</TD><TD></TD></TR>" & VbCr
Response.Write "<TR><TD></TD><TD></TD><TD align=right colspan=5> Nett Total </TD><TD align=right>" & strNetTotal & "</TD><TD></TD></TR>" & VbCr
Response.Write "<TR bgcolor=#b0c4de><TD></TD><TD></TD><TD colspan=6 align=right><Input Type=Button onclick=ConfirmChoice(); return false; value=""Delete Order""></TD></TR>"


If Dispatched AND CanConfirm then
	Response.Write "<TR bgcolor=#b0c4de><TD></TD><TD></TD><TD colspan=6 align=right><Input Type=Button id=Button_1 name=Button_1 value=""Confirm This Order""></TD></TR>"
else
	Response.Write "<TR bgcolor=#b0c4de><TD></TD><TD></TD><TD colspan=6 align=right><Input Type=Button id=Button_1 name=Button_1 disabled=True value=""Confirm This Order""></TD></TR>"
End If
Response.Write "</table></form>"

end if
Set objRs = nothing
Set objConn = nothing
%>
 
Use hidden form fields to submit it or response.write out the form field that may exist already.

Don't have time to read all the code. If you be more specific on when and where the ID is a more detailed reply may come about.

question: why are you response.write'ing "all" of your static HTML code out?


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
I agree....I used to response.write everything that was conditional, but it takes way more time and is more prone to TAG errors. ASP will work around it if you put it as follows:

Code:
<% IF myVar = True THEN %>
<P> Hello, your value was correct </p>
<% END IF %>

<A href="[URL unfurl="true"]http://www.easycgi.com/shared_hosting/?kbid=4815&img=easycgi_120x60_5.gif">[/URL]
<img src="[URL unfurl="true"]http://banners.easycgi.com/ShowBanner.asp?id=4815&img=easycgi_120x60_5.gif"[/URL] border=0></a>
 
Actually I believe onpnt meant replacing things like:
Code:
Response.Write "<script language=""JavaScript"" type=""text/javascript"">" & VbCr
Response.Write "<!--// "& VbCr
Response.Write "function ConfirmChoice()"& VbCr
Response.Write "{ "& VbCr
Response.Write "answer = confirm(""Are you sure you want to delete this order?"")"& VbCr
Response.Write "if (answer !=""0"") "& VbCr
Response.Write "{ "& VbCr

Response.Write "window.location = 'showorder.asp?switch=d&OrderID=" & strRecordid & "&recID=" & strRecordid & "'"& VbCr
Response.Write "} "& VbCr
Response.Write "}"& VbCr
Response.Write "//-->"& VbCr
Response.Write "</script>"& VbCr

with something like:
Code:
%>
<script language="JavaScript" type="text/javascript">
<!--// 
function ConfirmChoice()
{
answer = confirm("Are you sure you want to delete this order?")
if (answer !="0")
{

window.location = 'showorder.asp?switch=d&OrderID=<%=strRecordid%>&recID=<%=strRecordid%>'
}
}
//-->
</script>

(more stuff, more stuff)
%>

Esaping back into HTML to output a single line often isn't as efficient as just Response.Writing it. Escaping out to write many lines is generally more efficient than Response.Writing each one, especially when you have a concatenation on each line (concatenation is costly).

I'm fairly certain that was what the benchmarks said when we did them, though I don't think I ever followed up to determine where the break even point was between Response.Writing many times vs escaping to HTML.

 
There is another big plus with not using Response.Write all over the place - you can read it. The worst part of debugging is when you can't understand what it is doing or supposed to do.

Keep it clean and simple.

Inside your while loop you have this line
Code:
Response.Write "<Input Type=Button onclick=DeleteLine(); return false; value=""Delete"" id=Button1 name=Button1></TD></TR>"
which will be translated to this
Code:
<Input Type=Button onclick=DeleteLine(); return false; value="Delete" id=Button1 name=Button1></TD></TR>
Can you see what is wrong with this?

Why don't you send the id to the Javascript function like this?
Code:
%>
<Input Type=Button onclick='DeleteLine(<%=objRs("id")%>);' value="Delete" id=Button1 name=Button1></TD></TR>
<%
Then change your DeleteLine() function to accept a parameter like this (I am following Tarwin's lead and getting rid of the Response.Write):
Code:
<script language="JavaScript" type="text/javascript">
<!--// 
function DeleteLine(id)
{
  answer = confirm("Are you sure you want to delete this line?")
  if (answer)
  {
    window.location = 'showorder.asp?switch=dl&OrderID=" +id+ "&recID=" +id+ "&lID=" +id+ "'"
  } 
}
//-->
</script>
Although I don't know what the difference is between OrderID, recID, and lID. That is for you to figure out.

Hope this helps.

Einstein47
(For best results: hand wash in cold, tumble dry low. For not so good results: drag through puddles, pound on rocks, air dry on tree branch.)
 
Quick fix:
Code:
window.location = 'showorder.asp?switch=dl&OrderID=[COLOR=red]'[/color] +id+ [COLOR=red]'[/color]&recID=[COLOR=red]'[/color] +id+ [COLOR=red]'[/color]&lID=[COLOR=red]'[/color] +id

 
Thanks for all your ideas.

I used the
Code:
%>
<Input Type=Button onclick='DeleteLine(<%=objRs("id")%>);' value="Delete" id=Button1 name=Button1></TD></TR>
<%

method however the function at the top doesnt seem to pick up the id. Do I need to pass this through the browser when it refreshes ie. a hidden text box?

Andy
 
Did you modify your javascript like that last code box from Einstein displayed? Your existing javascript function wasn't expecting an argument or using it, so you needed to modify it to acceptthat argument. Your already doing an address change in your function, it's just a matter of giving it the right id to pass in the querystring.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top