$(document).ready(function() {
//Check City Value
var city_value = parseInt($(\"#city\").val());
if( city_value == 0) {
$(\"#state\").attr(\"readonly\", true)
You can do it in pure JavaScript (or Vanilla JS) without jQuery:
Set attribute readOnly
:
document.getElementById("state").readOnly = true;
and unset:
document.getElementById("state").readOnly = false;
Equivalent to object-oriented notation is also this array-oriented notation:
document.getElementById("state")['readOnly']
It is also important that in JavaScript all the properties are case sensitive, so it is important to remember about the large O
in the readOnly
property, otherwise it will not work...