开发者

How to block writing in input text?

开发者 https://www.devze.com 2023-01-09 21:57 出处:网络
I just creating a booking system and I want th开发者_高级运维at the users will choose a date from the calender and it\'ll show in input text - that I did!

I just creating a booking system and I want th开发者_高级运维at the users will choose a date from the calender and it'll show in input text - that I did!

Now I want to block the writing in the input text (just bring to calender writes there when the user choose a date). How do I do it? I guess JavaScript, but how? I dont know JS very wall..

Thank you very much!


Give your element the readonly attribute, this will disallow users to type anything into it. However, you will still be able to write to add through javascript for example when a date is chosen. Here is an example:

<input type="text" id="txt" readonly="readonly">

JavaScript:

var el = document.getElementById('txt');
el.value = "Testing......";

Working Demo


<input type="text" id="someId" disabled="disabled" />

The disabled property will prevent any user input, but you can still write to it via your javascript calendar method.


For those who wants to prevent typing but not having the disabled style, can try:

<input type="text" onkeypress="return false;"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号