Move focus when text field left empty?

Mike521

Freshman
Joined
May 3, 2004
Messages
27
Hey all,

I have a form with required text fields and such. When the user hits submit, they scroll down a bit and the text fields are not displayed on the screen. If they left the fields blank, they give the message I entered in the validator, but there is no alert to the user. So it appears that they click the button and absolutely nothing happens. If they don't scroll up and see the red warning messages, they may not figure out what the problem is.

Is there a way to either give them an alert window, or move the focus to the top of the page?

I'm thinking I can make a custom validator and have the same behavior as there is now, but also add a "response.redirect(#top)" or something along those lines, right?

Is there an easier way? Thanks :)
 
Easiest way is add a validation summary control to the form - just put it near the submit button.
Optionally you can also get it to display a messagebox as well as just listing the problems.
 
thanks damp, that was perfect :) it jumped me right back to the empty fields, I chose not to list them at the bottom, but it's nice that I can do that too.

Damp, just curious, I'm using dreamweaver to create this form, and several other asp.net things I've worked on. How much easier would it be if I was using visualstudio.net?
 
Not used Dreamweaver for quite a while now so I can't really give a good comparison.
Doesn't stop me having an opinion though ;) VS.Net does integrate well with the ASP.Net environment but it does have it's issues (reformatting your HTML being a big issue). The control integration (databinding, xsd generation etc) is very nice though.

However if you are in no real rush to convert over soon you may want to wait till next year when VS 2005 is released as the web development side of things gets a serious overhaul and many of the issues are fixed and considerable productivity enhancements have been added.
 
cool thanks :) I'm just noticing that I have to code all this by hand, and was thinking "hmm if I had vs studio would I just be dropping in all these things visually, saving myself a lot of time, etc"

coding by hand is nice though cause it'll teach me the intricacies (or force me to post lots of questions here lol)
 
Back
Top