469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

Form Select Default

384 256MB
I have a form with three fields for date of birth, day/month/year. When a user selects their dob, if not all details on the form are correct then the form is reloaded with any data entered already still there for the user, the problem i have is keeping the dob selected in the select fields, say a user select 21/04/1988 the three dob selects would default to dd/mm/yyyy which are the three default values, i need it to stay on the user selected date the user entered!??
Feb 15 '09 #1
6 4706
acoder
16,027 Expert Mod 8TB
Set the options as selected, e.g.
Expand|Select|Wrap|Line Numbers
  1. <option value="24" selected="selected">24</option>
Feb 17 '09 #2
Markus
6,050 Expert 4TB
Of course, HTML won't be able to tell you which option was previously selected; you'll need javascript (or something else) for that.
Feb 17 '09 #3
acoder
16,027 Expert Mod 8TB
I assumed that form reload meant a page reload, so you'd use server-side code to determine which option should be selected.
Feb 17 '09 #4
TheServant
1,168 Expert 1GB
Can I suggest using javascript to validate the form before it is submitted to the server to process. Not only does this save on server load, but it also is a quicker response for the user.
Basically you write some javascript code which checks that all the values entered are valid before it sends it to be processed. This is not 100% because a small percentage of users have javascript disabled, but it should work for most of your visitors... The worth while ones atleast :P
Google "Validate forms javascript" or something like that to get some sample codes.
Feb 18 '09 #5
ziycon
384 256MB
@TheServant
I've done all the validation through the PHP script as not everyone will have javascript enabled!

Go the 'selected' thing working, thanks!
Feb 18 '09 #6
TheServant
1,168 Expert 1GB
It is a good idea to have both javascript validation as well as PHP validation. It reduces the number of requests and saves the user time as I mentioned. Anyway, glad to hear it's working.
Feb 18 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Mark Watkins | last post: by
10 posts views Thread by Doug O'Leary | last post: by
3 posts views Thread by Steve | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.