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

Javascript If statement with ASP conditions

Status
Not open for further replies.

greg303

Technical User
Oct 28, 2003
24
US
Hi,
I have a message box javascript that determains what button the user clicks and returns certain messages based on that chocie. I also have asp script within the javascript logic that needs to run base on the choice, however the asp seems to run regardless of the button choice. Here is the code:
<script type="text/javascript">
var answer = confirm ("Do You Want To Remove <%=rs"prodname")%>?")
if (answer)
alert ("<%=rs("prodname")%> Removed, Thank You.")
<%strConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database/products.mdb")
Set objConn2 = Server.CreateObject("ADODB.Connection")
objConn2.open strConnect
sql = "update products set remove = true where prodid = " & remove
Set rs2 = objConn.execute(sql)%>

else
alert ("<%=rs("prodname")%> Not Removed.")
</script>

Basicly what is suppose to happen is if the user clicks 'yes' to the message box they with get the "Product Removed" message and the sql script will run, if they click no the "Not removed" Message will run but not the script, however the script runs regardless of the button clicked even though the message boxes will display the proper message. Any help on this would be appericated.

Thanks in advance.
 
Client-side JavaScript and Server-site ASP are two different animals. The server-side script always gets executed first, then the output of that is sent down to the client where any client-side script is ran.

You can't do it all at the same time like this. What you should do is have one ASP page that writes out the DB records. Then you can use JavaScript to confirm the user's choice. If they confirm, submit the form to a second ASP page where the product will be removed. At the bottom of that page, redirect them to a confirmation page or back to the first ASP page.

Adam

There's no place like 127.0.0.1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top