We help IT Professionals succeed at work.

JavaScript confirm box

311 Views
Last Modified: 2012-05-08
Im working on a web app using Classic ASP and a VB6 back end. When the user clicks update my code querys the database and pass back to the ASP page a countAll. If the count is zero I fired a confirm box. It ask the user if they want to proceed. When the user clicks cancel it reload the page and takes the user back to the previous data displayed. This part works fine. But when the user clicks OK the app just stops. I cant step through any code either. What I want to happen is the code continue to run and perform the update. I think I need an else or something to tell it to continue.
Comment
Watch Question

Author

Commented:
my code

<script language="JavaScript">
<!--
var answer = confirm ("There is not a WorkSpec for this Task Number. Do you want to continue?")
if (!answer)
window.top.location.href='AirPartInfoFS.asp?NP=<%=Request.QueryString("NP")%>';      
                                        
                                              
//-->
</script>
                                        
Top Expert 2009

Commented:
>> I think I need an else

you said it yourself.

<script type="text/javascript"> 
var answer = confirm ("There is not a WorkSpec for this Task Number. Do you want to continue?");
if (answer)
{
	alert("Yes");
	// code here when the answer is true
}
else
{
	alert("No");
	// code here when the answer is a no
}	
</script>

Open in new window

Author

Commented:
is there code for a "Resume" if the user clicks OK

This is just one of many checks. What I'm wanting it to do is just carry on through the code and do the update.
Top Expert 2009

Commented:
if (answer)
{
// put your code here to update
}
else
{
// This part when the user clicks cancel you will refresh the page
window.top.location.href='AirPartInfoFS.asp?NP=<%=Request.QueryString("NP")%>';      
}

Author

Commented:
tried that already. I have about 100 lines of code for the update with two more calls to the data base to validate other info the user inputs. It throws an error when I try this
Top Expert 2009

Commented:
what error?

Author

Commented:
runtime error ';'

Author

Commented:
i have about 100 lines of ASP code left to run that has validation and calls to the database. You are telling me to put that ASP update code in the else statment of the javascript?
Top Expert 2009

Commented:
I assume the 100 lines of code which you are mentioning is modularized and is in an function... which might be called somewhere else?

you could just call the function in the else loop(according to your logic in the first post)

I hope this really helps

Author

Commented:
the javascript is nested about half way through the upate function. I make a call to the database to see if a record is present. then I have a line that checks if it's = to 0. What I would really like to do is in the else statement just let it go back to the code and be able to step through it.

If lctDepot.CountAll = 0 Then
' Whoops, no match, ask the user if they want to continue.
%>
    <script language="JavaScript">
<!--
          var answer =  confirm ("There is not a WorkSpec for this Task Number. Do you want to continue?")
         if (!answer)
      window.top.location.href='AirPartInfoFS.asp?NP=<%=Request.QueryString("NP")%>';      
                                        
//-->
</script>
                                        
<%
Set lctDepot = Nothing
'Response.End()
Else

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.