PDA

View Full Version : Popping open a window using javascript & asp - or just asp?


jpmad4it
02-07-2008, 04:27 PM
Hi there

I have an asp script that validates information sent from an HTML form. Basically if the info is incorrect or not validated when the user hits the sumbit button, I want to popup a window with an error message. At the moment i'm trying to call a link using a javascript method:

I changed the code from:

If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

to this:

If (validationOK=false) Then Response.Redirect("<a href='javascript:PHOTO_WINDOW('error.htm?')'>" & EmailFrom)

The javascript for this is in a file called popup.js which I have included at the top of my asp page using:

<!--#include file="popup.js"-->

Can you see what I am trying to do? It would be really nice to popup a little window within the page where the form is included, instead of using a javascript popup window. Can anyone help?

Much appreciated

Johnny

Spudhead
02-08-2008, 11:07 AM
No, you can't do it. Or at least, you can't do it like that.

Response.Redirect() sends a command to the browser to go and request a URL. You can't put HTML in there, it's not going to know what to do with it.

What you COULD do is send them back to the form page, with something in the querystring to indicate the error. The form page checks for this querystring value and writes some javascript popup-window code if it's there.

Of course, the downside of that approach is that the redirect will likely wipe all the form values that the user just entered, so as well as getting a popup window in their face, they'll have start filling in the form all over again.

The problem is really that you're trying to tie server-side validation to client-side response. The way I'd probably do it is some sort of AJAX method to submit the form and then either display an error message or redirect to a thankyou page.

jpmad4it
02-08-2008, 11:21 AM
No, you can't do it. Or at least, you can't do it like that.

Response.Redirect() sends a command to the browser to go and request a URL. You can't put HTML in there, it's not going to know what to do with it.

What you COULD do is send them back to the form page, with something in the querystring to indicate the error. The form page checks for this querystring value and writes some javascript popup-window code if it's there.

Of course, the downside of that approach is that the redirect will likely wipe all the form values that the user just entered, so as well as getting a popup window in their face, they'll have start filling in the form all over again.

The problem is really that you're trying to tie server-side validation to client-side response. The way I'd probably do it is some sort of AJAX method to submit the form and then either display an error message or redirect to a thankyou page.

Hey thanks for that. I've decided to leave the initial system in place. If the data is incorrect, the error.htm page displays asking them to check the form. When they go back, the user's data is saved in the form which is handy. Once they fill out all required fields correctly, success.htm is displayed and the data is sent. I just wanted to remove having to redirect to a new page if the form data was incorrect.