We help IT Professionals succeed at work.

Page reload on form submission with Javascript alert stops page from rendering

Brad Bansner
Brad Bansner asked
on
514 Views
Last Modified: 2013-12-07
In the attached HTML file... if you fill out this form, it points to itself for validation on the server side. If not all required fields are filled in, in the <head> area this is inserted:

<script language="javascript" type="text/javascript">
alert ("One or more required fields was not filled in, please answer all questions.");
</script>

The rest of the page is just HTML. In all browsers EXCEPT Firefox, this works fine and the form is redisplayed so the user can fill in the required fields. However, most of the time, in Firefox... I just get a blank white screen. The attached file is the page source when this happens. The code looks fine, but Firefox stops rendering the page for some reason. I can't get any other browser to do this, and it happens in both Windows and Mac versions of Firefox.

Any workaround for this? Thank you!

temp.htm
Comment
Watch Question

Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Why alert? Insert it on the page instead in a bold red header
Brad BansnerWeb Developer

Author

Commented:
The alert gets people's attention. Although your comment may be accurate, it doesn't explain why this is happening in the first place. It shouldn't be a problem, and I have used this same technique for years on many websites, so its sort of a big concern for me.

Commented:
If you use classic ASP then after the Response.Write ("<script> alert ('....')</script>")

do a Response.End
or if you set buffer = true the do the Response.flush
Brad BansnerWeb Developer

Author

Commented:
The response buffer controls what the server is sending to the client, but it has nothing to do with the actual final rendering of the page, does it? That wouldn't change the page source at all.
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Brad BansnerWeb Developer

Author

Commented:
Adding the window.onload and function seems to have fixed it! Thanks.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
YW :)
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.