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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP variable to client side Script

Status
Not open for further replies.

AGNEW2PRG

Technical User
Aug 5, 2003
98
AE
Hi,

Please could you help with the question below?
I am trying to pass the variable 'strRecordDtls' to the client. I am trying to get a message box to popup on the client asking the user to confirm deletion of the record.

Is this possible? If so how do you do this ?

Many Thanks

*******************************************************

<%
Dim adoCon
Dim rs
Dim strSQL
Dim lngRecordNo

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../db.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT TBLCONTACTS.* FROM TBLCONTACTS WHERE ID=" & lngRecordNo
rs.LockType = 3

rs.Open strSQL, adoCon

strRecordDtls = (rs("CONTACT"))

' response.write "MsgBox " & (strRecordDtls)

rs.Delete

rs.Close

Set rs = Nothing
Set adoCon = Nothing

Response.Redirect "delete.htm"
%>
 
You need to do it on the previous page. ASP is server-side, therefore it executes before the browser ever gets any content. In fact, the browser doesn't even fire the internal OnLoad event until it has already received all of the content from the server. So as the client is finishing up the process of displaying the web page, the server is already done with the ASP script, is closing the file, and is cleaning up any left over variables or memory use.

My assumption is that you have a "delete"link on the previous page that links to this one. What you would want to do is build a little piece of javascript into each delete link that uses the confirm() function. So something like:
Code:
Response.Write "<a href=""deletepage.asp?id=" & rs("ID") & """ onClick=""return confirm(""Are you sure you want to delete the record for " & rs("Contact") & "?"");">Delete</a>"

The return before the call to confirm basically takes whetever is returned from the confirm function (true/false) and returns it from the onClick event. if the value is a true, eveythign keeps working the way you would expect. if the value is a false, then the browser will stop executing anyfurther event handlers for the click on that object (for instance, this being a link the next handler will be to request the linked to page, witha false the anchor will not change the page).

 
Hi Tarwan,

the link is on the previous page is as follows

Response.Write ("<a href=""deletepage.asp?ID=" & rs("ID") & """>")
Response.Write ("<img src='/images/delete.gif' width='9' height='9' border='0'>")

I have now changed it to

Response.Write "<a href=""deletepage.asp?id=" & rs("ID") & """ onClick=""return confirm(""Are you sure you want to delete the record for " & rs("Contact") & "?"");">
</a>"

Still having problems.. where am I going wrong?

Regards
 
My bad, I made you put double quotes inside the javascript function when the onClick already is using double quotes :p

It should look like:
Code:
Response.Write "<a href=""deletepage.asp?id=" & rs("ID") & """ onClick=""return confirm([highlight]'[/highlight]Are you sure you want to delete the record for " & rs("Contact") & "?[highlight]'[/highlight]);">...


Sorry about that,

-T

 
I prefer this way -
<a href="deletepage.asp?id=<%=rs("ID")%>" onClick="return confirm('Are you sure you want to delete the record for <%=rs("Contact")%>?');">

That way you can enter the text as a much more convinient JavaScript code, without having to write it through ASP, and still, entering an ASP variable into it..
 
Thank you for sharing, unfortunatly with over 20,000 members in the ASP forum it's hard to remember everyone's preferences, but I'll try to keep that in mind if you post later.

 
:)
If you look closely, I wasn't the one posting the question.
Just offering a more convient way to implement the solution...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top