javascript/asp help

Sorry, It’s me again! And knowing my luck this isn’t going to be simple, but here goes…

I have a javascript function (see code) which runs from a link from a table of returned records. The link looks like “<a href=javascript:resurrect(”& rs(“clientid”)&")>Resurrect</a>" (this just an extract of a full table line, not the whole line)



<script>
function resurrect(id)
{
 if (confirm("Are you sure!")) 
 {
<%

set RS = Conn.Execute("update clients set requeststatusid=1 where clientid = "& id
%>
 location.reload(true)
 }
}
</script>


The problem is: The browser seems to run (or try to run) the asp portion of the code regardless of whether the condition in the javascript portion has been met. It stops the page from loading at all… even thought the function is supposed to only run when the link has been clicked, and the asp line is only supposed to run or be parsed when ‘yes’ has been clicked.
What I am aiming for is for the database to be updated when the link is clicked, and then the page to be refreshed (so that the link disappears because it is not shown if ‘requeststatusid’ is 3 (rejected))

Sometimes the page is the result of a database search using a form on the page. I want the page to keep the same results when ‘location.reload(true)’ is run. rather than going back to the ‘default’ page after the table update.

I’ve gone and overcomplicated the OP again.
All I want to do is stop the ASP portion from being run by the browser if the condition hasn’t been met.

Javascript is client-side and ASP is server-side. So ASP is going to be run before Javascript even come into the picture. Conversely, if you want to put some sort of ASP like <%=SomethingID%> in the middle of some JS, it can be done.

You will need to either pass variables to the ASP, and say “If whatever Then <run db script>”) and NOT INVOLVE JS AT ALL…

Or you need to use Javascript to make the link send a querystring with your data in it to another ASP page with your ASP on it if certain conditions are met, then have the ASP page send you back to the original page once it’s done doing its processes.

Or, use return confirm(‘Are you sure?’) on your link. If they say no, then nothing happens.

You’re mixing up your code contexts. ASP code runs on the server; javascript runs on the client/browser. ASP does NOT run on the browser.

If your page is called, any ASP code is going to run *prior * to the page being delivered to the browser. That’s why your database update is happening regardless of whether you call the function or not. It’s already happened before you even see the page.

Bolding mine: Is there a way of doing that where it sends you back to the original page and maintains the original page’s ‘get’ variables?

You’d have to send the GET variables over to the ASP page in the qstring or as a form field, and then back again to the original page as part of the qstring in “Response.Redirect”

So if you are landing on a search page with the results for the search string “my butt” then your link that sends stuff to the asp page should be like “updatedatabase.asp?updatecode=1&searchstring=my%20butt” … the updatedatabase.asp page would grab and hold “searchstring”, process whatever it needs to process then Response.Redirect “searchresults.asp?searchstring=my%20butt”

Clear as mud?

Yes. but before you answered I settled on the following in a different asp called by the first one. I’ve tested it and it works a beut…



<!-- #include file="includes\db.asp" -->

<%

qsid      = request.querystring("id")
qsmode    = request.querystring("mode")
qsconfirm = request.querystring("confirm")

if qsid <> "" then
	select case qsmode
			case "resurrect" 
				if qsconfirm <> "yes" then
					response.write "<a href=ews_account_update.asp?id=" &qsid & "&mode="&qsmode&"&confirm=yes>Confirm</a>"
				else
					set RS = Conn.Execute("update clients set requeststatusid=1 where clientid = "&qsid)
					finish()
				end if
			case "change_ac_num"
			case ""
			'do nothing!
		end select
end if
%>

<%Sub finish()%>

<script>
window.opener.location.reload(true) 
window.location = 'ews_account_update.asp'

<!--doing "window.location = 'ews_account_update.asp'" ensures that the address bar doesn't contain the full list of variables in case "window.close()" fails-->

window.close()
</script>

<%End Sub%>