I have tried the following codes to set a textbox property to readonly but none of them is working. Can anyone tell me how to do it?
document.getElementById("phone_numbers").disabled=true;
document.getElementById("phone_numbers").readonly=true;
document.getElementById("phone_numbers").readOnly=true;
document.getElementById("phone_numbers").readOnly=readOnly;
document.getElementById("phone_numbers").readOnly=readonly;
document.getElementById("phone_numbers").readonly=readonly;
document.getElementById("phone_numbers").readonly=readOnly;
document.getElementById("phone_numbers").setAttribute('readonly', 'readonly');
document.getElementById("phone_numbers").setAttribute("readonly", "true");
EDIT
While I was editing my question to write more detail I realized what the problem was. I made a silly mistake. This was my original HTML code.
<input name="phone_numbers">
And I changed it to
<input id="phone_numbers">
And it worked!
By the way following are the functions that are actually working.
document.getElementById("phone_numbers").disabled=true;
document.getElementById("phone_numbers").readOnly=true;
document.getElementById("phone_numbers").setAttribute('readonly', 'readonly');
document.getElementById("phone_numbers").setAttribute("readonly", "true");
Your third line worked for me: JSFiddle
HTML
<input id="phone_numbers" type="textbox"></input>
Javascript
document.getElementById("phone_numbers").readOnly=true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With