View Full Version : How to handle the result of a JS Confirm
jamesd
05-06-2003, 01:08 PM
Hi,
I'd like to use an JS confirm box in my code and then perform an action based on whether it's true or false.
I was thinking of something like this...
response.write"<script language=""javascript"">" & VbCrLf
response.write"confirm(Are you sure?');" & VbCrLf
response.write"</script>" & VbCrLf
I then want to say if true to action1 else do action 2 but I don't know how to get at the result of the confirm box.
Can anyone help?
Many thanks,
James.
david7777
05-06-2003, 01:22 PM
Combining the 2 like i think you want to is not possible, but you can do it like this:
<script>
if(confirm("Are you sure?")){
location.href="yesLink.asp"
}else{
location.href="noLink.asp"
}
</script>
Does that help?
jamesd
05-06-2003, 01:29 PM
Thanks for the reply.
Ideally I'd like to return to the code of the existing page and execute further code based on the outcome.
Is this a basic limitation whereby you can't pass data from a javascript function to asp?
david7777
05-06-2003, 01:42 PM
Unfortunately it is a limitation.
the best thing to do would be to put a case statement in your code and use querystring:
'page.asp
dim a = trim(request.querystring("a"))
select case a
case "yes"
response.write("Answered yes")
case "no"
response.write("Answered no")
case else
' code if there is no answere - ie: what must normally show.
response.write("<s" & "cript>if(confirm('Are you sure?')){")
response.write("location.href='page.asp?a=yes';}else{")
response.write("location.href='page.aso?a=no';}</script>")
end select
jamesd
05-06-2003, 01:49 PM
OK, thanks David, looks like I need to use separate pages as you say.
whammy
05-07-2003, 12:40 AM
What exactly are you trying to do?
I use this kind of stuff all the time.
Roy Sinclair
05-07-2003, 02:42 PM
James, I see that you've understood it already but for the benefit of any lurkers who might not have figured it out:
A limitation of any host based scripting is that it is not directly interactive with the user. By directly interactive I mean that it can't request a response from the user as it creates output and then create further output in the same page based on the user's response. The communication with the user is based on the sending of whole pages to the user and receiving the user's response via form submits and/or page links. Effectively, the script on the host will complete all processing before the user ever gets a chance to interact with the page created by the script and until a link or form is activated on the page the server side script is no longer running.
Understanding how this works is essential for planning your web pages. When you don't understand this you may end up designing a web site that isn't possible and wasting your time trying to get it to work.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.