views:

38

answers:

2

Hi,

I have a input field and on clicking that I will show a date picker to select the date. I would like to always make this field select using from that picker and not by typing. the reason is, i am just modifying this one field and don't want to touch the whole code to validate this field. i have given enough drop down options for the users to select from the drop down so i prefer to accept input using this selection and not by typing. if i allow typing , there are chances that users can change the year to a past year and that overrides everything.

regards

+1  A: 

you could try using a button for the datepicker and on selection of a date set a hidden field and a visible label.

Look at some of the examples in and around this:

http://jqueryui.com/demos/datepicker/#icon-trigger

Luke Schafer
this is the same link i used for date picker but thanks for pointing out the icon-trigger option. for some reason still the field is editable by typing.in some sites, they have this field });</script><input type="text" id="datepicker" name="date">.i store the i/p to db
Jay
+3  A: 

The problem with forcing users to use a date picker is that, short of using HTML5 form inputs, you're forced to use JavaScript to make the picker work. If JavaScript is disabled, then your user will have to input the value by hand, defeating whatever edit protection you put on the field in the first place. That input would have to be validated anyway.

In addition, leaving your input without validation could leave you vulnerable to SQL injection attacks, where a visitor uses some other tool (like Firebug, for instance) to manually post unfiltered data through that input and possibly into your database.

Look, I know form validation is a pain, but trying to lock down your input because you don't want to filter it is a recipe for trouble.

derekerdmann
I agree with your point. my approach will lead to some injections. I missed the firebug option and things like that.i will work on the validation. its little messy as other parts of the code are already present and i will end up with modify all.
Jay