Skip to main content

Sometimes you have some input fields you want to show to the end user but not allow them to edit.  For example a profile page where they can update their name, phone number, change their password, but you may want to restrict them from modifying their email address.

Whatever the case may be here’s a simple jQuery example of how to disable a text input field on page load.

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Example of how to disable an input field on page load using jQuery">
    <meta name="author" content="Projex">

    <title>jQuery Disable Input on Page Load | Prodjex Web Development and Consulting</title>

    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/signin.css" rel="stylesheet">

        body{background-color: grey;}
        p{color: #fff;}

<body class="text-center">

<div class="container">
    <div class="col-md-12">
        <img src=""><br><br>
        <div class="form-group">
            <input class="form-control" type="text" name="fname" placeholder="First Name"/>
        <div class="form-group">
            <input class="form-control" type="text" name="lname" placeholder="Last Name"/>
        <div class="form-group">
            <input class="form-control" type="text" id="exampleID" name="email" placeholder="Email Address"/>

<script src=""></script>
<script src="" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>



Notice at the bottom of the code


This sets the property of “disabled” on the input field that has the ID “exampleID”.

You can check out the demo here.

View the Prodjex Web Development form discussion on how to Disable Input Field on Page Load Using jQuery.

Leave a Reply