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

Pass recordset field to client side VBScript 1

Status
Not open for further replies.

cruford

Programmer
Dec 6, 2002
138
US
I have searched for this and didn't find anything real helpful. Basically I have a ASP page that just loops through a recordset and writes the row. At the end of each row is a DELETE hyperlink that pops up a message box confirming the delete (see code below). Is it possible to pass the recordset value (i.e. RS.fields("FirstName") & " " & RS.fields("LastName")) to the client side script so I can display it in the message box? Or is it just easier to make the delete hyperlink point to another page that has only the record to be deleted listed? The code in red is where it is writing the DELETE hyperlink, can I pass the field value from there?

Code:
<script language="vbscript">
	Sub Del_OnClick()
		Dim intResp
		intResp = MsgBox("Do you really want to delete this record?", vbYesNo,"Confirm Delete")
		If intResp = vbYes Then
			window.event.returnvalue = True
		Else
			window.event.returnValue = False
		End If
	End Sub
</script>

And the code creating the rows and link:

Code:
Response.Write "<tr class=""TDBody"">"
If IsNull(RS.Fields("LoggedDate")) Then	response.write "<td>&nbsp;</td>"
Else
	Response.Write "<td>" & RS.Fields("LoggedDate") & "</td>"
End If
response.write "<td>" & RS.Fields("FirstName") & "</td>"
If isnull(RS.Fields("MiddleInitial")) Then 			Response.Write "<td>&nbsp;</td>" 
Else 
	Response.Write "<td align=""center"">" & RS.Fields("MiddleInitial") & "</td>"
End If 
Response.Write  "<td>" & RS.Fields("LastName") & "</td>"
If IsNull(RS.Fields("Other")) Then			response.write "<td>&nbsp;</td>"
else
	response.write "<td>" & RS.Fields("Other") & "</td>"
End If
If isnull(RS.Fields("SignedCopy")) Then
	Response.Write "<td>&nbsp;</td>"
Else
	Response.Write "<td>" & RS.Fields("SignedCopy") & "</td>"
End If
If isnull(RS.Fields("AOBDate")) Then
	Response.Write "<td>&nbsp;</td>"
Else 
	Response.Write "<td>" & RS.Fields("AOBDate") & "</td>"
End If
Response.Write "<td>" & RS.Fields("SalesRep") & "</td>"
Response.Write "<td><a class=""popup"" href=""javascript:pop('Diabetics_Notes_Popup.asp?ID=" & RS.Fields("ID") & "&" & uUrl & "')"">Notes</td>"
[COLOR=red]
If Request.Cookies("Groups")("Med4PodLeaders") = "YES" Then
        Response.Write "<td><a style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Edit&ID=" & RS.Fields("ID") & "&" & uUrl & """>Edit</a></td>"
	Response.Write "<td><a onClick=""Del_OnClick()"" style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Delete&ID=" & RS.Fields("ID") & "&" & uUrl & """>Delete</a></td>"
Elseif Request.Cookies("Groups")("DomainAdmins") = "YES" Then
        Response.Write "<td><a style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Edit&ID=" & RS.Fields("ID") & "&" & uUrl & """>Edit</a></td>"
Response.Write "<td><a onClick=""Del_OnClick()"" style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Delete&ID=" & RS.Fields("ID") & "&" & uUrl & """>Delete</a></td>"
Elseif Request.Cookies("Groups")("Med4_ITDept") = "YES" Then
Response.Write "<td><a style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Edit&ID=" & RS.Fields("ID") & "&" & uUrl & """>Edit</a></td>"
Response.Write "<td><a onClick=""Del_OnClick()"" style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Delete&ID=" & RS.Fields("ID") & "&" & uUrl & """>Delete</a></td>"
End If
Response.write "</tr>"
RS.MoveNext
[/color]
 
I hope this helps cruford.

looking thru your code it seems that in

<code>
Response.Write "<td><a onClick=""Del_OnClick()"" style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Delete&ID=" & RS.Fields("ID") & "&" & uUrl & """>Delete</a></td>"

</code>

you call your del_onclick function and have it go through its process. Normally I dont think VBScript is as strong in functions as javascript is so I use that in place of it when I want to pass variables to the function.

EG.
I would create this function in a .js file
<code>

function DeleteUser(ID,NAME) {
if (confirm("Delete user: "+ NAME + " ?" )) {
window.location.replace("user_del.asp?ID=" + ID );
}
}

</code>

In your case I would remove the ID,NAME properties and use FIRST,LAST and pass it in your script like so

function DeleteUser(RS.fields("FirstName"),RS.fields("LastName"))


works exactly the way you want it and redirects it to the right page. If you want to add another property then you can do this too by adding another property like FIRST,LAST,ID if you want to pass an identifier for an autofield if you want....
 
Yeah my js skills suck that is why I use VBscript. I did what you suggested and changed it to javascript. So this is what I have now:

Code:
<script language="JavaScript">
   var pageName;

   function pop( pageName ) {
     popup=open( "[URL unfurl="true"]http://M4H/Sales/"[/URL] + pageName, "popup", "width=475,height=250,scrollbars=yes,resizeable=no,top=175,left=175" );
   }

	function DeleteAccount(ID,FIRST,LAST) {
  	if (confirm("Delete Account: "+ FIRST + " " + LAST + " ?" )) {
    	window.location.replace("Diabletics_Main.asp?CMD=Delete&ID=" + ID );
    }
  }
</script>

Delete Statement:

Code:
Response.Write "<td><a onClick=""DeleteAccount(" & RS.fields("ID") & ", " & RS.Fields("FirstName") & ", " & RS.Fields("LastName") & ")"" style=""text-decoration: none; color: navy; font-size: 8pt"" href=""Diabetics_Main.asp?CMD=Delete&ID=" & RS.Fields("ID") & "&" & uUrl & "&Pod=NoGroup"">Delete</a></td>"

When I view the source it all looks correct but when I click the delete it pops up an error message like this:


Error: 'DOROTHY' is undefined

Dorothy is replaced by whatever the RS.Fields("FirstName") is on each record but the same error for every one. Now after I click OK to the error message it deletes the record and moves to the correct page. Can you tell me how I should be declaring these in the javascript?
 
your function is correct but here is what i'd use in the response field.

Code:
<%Response.Write "<td><a style=""cursor:hand;"" onclick=""DeleteAccount('" & RS.fields("ID") & "', '" & RS.Fields("FirstName") & "', '" & RS.Fields("LastName") & "') style=""text-decoration: none; color: navy; font-size: 8pt"">DELETE</a></td>""%>



what is DOROTHY used for in your code make sure if its a variable that it's included with a dim in case you're using option explicit
 
Ok I got it now I had some quotes in the wrong place. This works great now. Thanks for your help and here's a star.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top