Prevent editing a form field without disabling the field

I'm currently working on a page that has a date picker for one of the fields.

One of my clientโ€™s requirements is to prevent the user from manually editing the field. Only the date picker can be used. (jQuery DatePicker)

I meant to disable the field and use a hidden field to store data (disconnected from the ton send data object on post). This sounds a little strange for something that can be done using javascript. I'm sure.

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

+4
source share
2 answers

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

+15
source

You can also access this property using javascript if necessary:

document.getElementById("myTextBoxID").readOnly = true; 
+4
source

Source: https://habr.com/ru/post/1306138/


All Articles