How to use JQuery to make a field Read Only

Written by Ian Carnaghan · 15 sec read >

Say you have a input text field as below

 <input type="text" name="inputField" id="inputField" />

As soon as the page has finished loading we will make use of JQuery to make the input field Read Only so that the field can’t be edited by the user.

We do it like this

<script type="text/javascript">
   $('#inputField').attr('readonly', 'readonly');

Last Updated On March 21, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

Notify of