最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent form field to be edited without disabling field - Stack Overflow

programmeradmin1浏览0评论

I am currently working on a page that has a date picker for one of the field.

One of the requirements by my client is to prevent the user from editing the field manually. Only the date picker would be possible to be used. (jQuery DatePicker)

I had in mind to disable the field and use an hidden field to store the data (disabled from object ton send data on post). This sounds a bit wacky for something that could be done by javascript I'm pretty sure.

So the big question, in javascript is it possible to prevent manual edition of a field without stopping datepicker plugin?

I am currently working on a page that has a date picker for one of the field.

One of the requirements by my client is to prevent the user from editing the field manually. Only the date picker would be possible to be used. (jQuery DatePicker)

I had in mind to disable the field and use an hidden field to store the data (disabled from object ton send data on post). This sounds a bit wacky for something that could be done by javascript I'm pretty sure.

So the big question, in javascript is it possible to prevent manual edition of a field without stopping datepicker plugin?

Share Improve this question asked Apr 6, 2010 at 15:19 ErickErick 6,08910 gold badges46 silver badges61 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

Instead of disabling the field, just add the readonly attribute. It will have a similar effect as disabling the field, but without the need to store the value to a hidden field.

You can also access this property with javascript if needed:

document.getElementById("myTextBoxID").readOnly = true;
发布评论

评论列表(0)

  1. 暂无评论