PDA

View Full Version : IF.. Then... JS


christrinder
04-01-2003, 11:54 AM
Hello,

I've got an IF statement, and in the THEN part of it, I want the server to use a JS alert box before response.redirecting... any ideas how I integrate the JS? Obviously the below code dosn't work.

<%
If ... THEN
response.write "javascript:alert('message')"
response.redirect "javascript:history.back()"
End If
%>

raf
04-01-2003, 12:16 PM
Hmm. Never used it, but Vbscript has a Msgbox() function, that returns a value, according to the clicked burron. So you probably can use that, and check for the returned value before redirecting. (more info below)

if bla=bla then
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")
If MyVar=1 then
Response.redirect(“url”)
Else
Response.redirect(“url2”)
End if
End if


Personally, i just load an html-page (i hate popup’s and message-boxes etc) with a backlink or a countdownscript (javascript). Sort a like here, after you post.

More info on MsgBox from helpfile
---------------------------------------------------------------------
MsgBox Function Language Reference Version 1
See Also

Description
Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.
Syntax
MsgBox(prompt[, buttons][, title][, helpfile, context])
The MsgBox function syntax has these arguments:
Part Description
prompt String expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return–linefeed character combination (Chr(13) & Chr(10)) between each line.
buttons Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. See Settings section for values. If omitted, the default value for buttons is 0.
title String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar.
helpfile String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. If helpfile is provided, context must also be provided. Not available on 16-bit platforms.
context Numeric expression that identifies the Help context number assigned by the Help author to the appropriate Help topic. If context is provided, helpfile must also be provided. Not available on 16-bit platforms.
Settings
The buttons argument settings are:
Constant Value Description
vbOKOnly 0 Display OK button only.
vbOKCancel 1 Display OK and Cancel buttons.
vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
vbRetryCancel 5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1 0 First button is default.
vbDefaultButton2 256 Second button is default.
vbDefaultButton3 512 Third button is default.
vbDefaultButton4 768 Fourth button is default.
vbApplicationModal 0 Application modal; the user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box.
The first group of values (0–5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512, 768) determines which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value for the argument buttons, use only one number from each group.
Return Values
The MsgBox function has the following return values:
Constant Value Button
vbOK 1 OK
vbCancel 2 Cancel
vbAbort 3 Abort
vbRetry 4 Retry
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No
Remarks
When both helpfile and context are provided, the user can press F1 to view the Help topic corresponding to the context.
If the dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel. If the dialog box contains a Help button, context-sensitive Help is provided for the dialog box. However, no value is returned until one of the other buttons is clicked.
The following example uses the MsgBox function to display a message box and return a value describing which button was clicked:
Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example") ' MyVar contains either 1 or 2,
' depending on which button is
' clicked.

Roelf
04-01-2003, 01:03 PM
but the messagebox appears on the computer where the code is executed -> the server.
Who will click the ok or cancel buton??

raf
04-01-2003, 02:21 PM
Don't know. Never used it (like i said before). If i can find the time, i'll experiment with it. (think you can write it to the browser, set a flag, return the value, check for the flag and redirect if the flag was set and the right value was returned.)

Or go browsersided javascript. I presume it comes down to: use a javascript redirect and just write that code to the browser like you would do in a hardcoded page. (both messagebox and redirect should be sent to the browser and executed there)

allida77
04-01-2003, 02:31 PM
Just write the client side code out to the browser.

<%
If 1=1 THEN
response.write "<script>alert('message');history.back();</script>"
End If
%>

whammy
04-02-2003, 12:16 AM
What allida77 said - I often just display completely different HTML (using subroutines) depending upon my logic (which is especially useful posting a form to itself!), i.e.:


<%
if something = true then
call displayHTML1()
else
call displayHTML2()
end if

sub displayHTML1()
'put some html to display here
end sub

sub displayHTML2()
'put some html to display here
end sub
%>


P.S. Of course I would name your subroutines something a little more descriptive...

Roy Sinclair
04-02-2003, 07:31 PM
What you are asking for simply isn't possible. Think about it for a second, you have your ASP code running on the server and as that code runs you are going to try to ask the user (who happens to be on a different computer entirely) a question so that you can customize the rest of the web page according to their response.

The basic problem is that your query/response method for web pages is done using web pages and forms. In order to ask a question of the client you must send a WHOLE web page and then receive the answer via a form. You can't send half a web page and then wait for a response because there's no interactive response method defined for that sort of use and the browser likes to receive whole pages before it lets the user get very involved with a page anyway.

The key to remember is that all of your server side code may have completely executed before your client side code will even start running and the response to any user actions is going to be the result of a form submit or some equivalent.