How to use JQuery to make a field Read Only

No Comments

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">
 
jQuery(document).ready(function($){
 
   $('#inputField').attr('readonly', 'readonly');
 
})
 
</script>

Image Credits: Photo by Isis França on Unsplash.

Last Updated On March 21, 2018

Related Articles

No results found

Leave a Reply

avatar
  Subscribe  
Notify of
Menu
Copy link