In case of textbox can readOnly property could be in toggle form?

i want the readOnly property for two textbox fields. When click on '#text1' the '#text2' should have false readonly property and when click on '#text2' the '#text1' readonly will be false. By default both textboxes have true readOnly. Is it possible?

<input type="text" id="text1" />
<input type="text" id="text2" />

Answers 1

  • Try this

            <input type="text" id="text1" onclick="text1()" /> 
            <input type="text" id="text2" onclick="text2()" />
            <script type="text/javascript">
                function text1() {
                    $("#text1").prop("readonly", true);
                    $("#text2").prop("readonly", false);
                function text2() {
                    $("#text2").prop("readonly", true);
                    $("#text1").prop("readonly", false);

Related Articles