Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Read Only property for input field

The thing that I'd like to happen is that when the value of the status field is Paid the input field fines should be read-only. How to achieve this?

This is my form:

This the form look like

This is my code:

   <div class="form-group">
                    <label for="status" class="col-sm-3 control-label">Status</label>
                    <div class="col-sm-9">
                    <input type="text" class="form-control" id="status" value = "Paid" name="status"  readonly>
              </div>
                    
                </div>


             
             <div class="form-group">
                    <label for="fines" class="col-sm-3 control-label">Fines</label>
                    <div class="col-sm-9">
                    <input type="text" 
                               class="form-control" id="fines"  name="fines"   required>
                    </div>
                </div>

Javascript line of code:

<script type = "text/javascript">

$(document).ready (function(){
$('input[type=text][name=status]').change(function() {
    if (this.value == "Paid") {
        $("#fines").prop("readonly",true);
    }
    else{
        $("#fines").prop("readonly",false);
    }
});
}); 
</script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Seeing as you're status field is set to readonly on load, I'd imagine you want to trigger a change event instantly.

$(document).ready (function(){

  // setup a variable for multi-use
  var $statusField = $('input[type=text][name=status]');

  // watch for changes to the statusField
  $statusField.change(function() {
    
      // simpler check for paid status
      $('#fines').prop('readonly', this.value === 'Paid');
  });
  
  // trigger a change on ready
  $statusField.change();
 
});

This way you have access to trigger the change programatically but also have the ability to watch the status field. I've also cleaned up your code a little bit!

about 4 years ago · Juan Pablo Isaza Report

0

try like this

if ($(this).val() == "Paid") {
            $("#fines").attr("readonly",true);
        }
        else{
            $("#fines").attr("readonly",false);
        }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!