Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text field make editable, not editable using jquery

Tags:

html

jquery

I am using display tag for creating tables and using jquery to make a textfield editable and remove readonly property.

<script type="text/javascript">
$(function(){
    $(".makeEditable").click(function(){
        $('input:text').removeAttr("readonly");    
    });
    $(".makeNonEditable").click(function(){
        $('input:text').attr("readonly", "readonly");    
    });               
})
</script>

Here is the code for table and column with textfield

<display:table name="loadData" style="float:left;">
    <display:column title="User Defined" class="colId">
    <input type="text" value= "" name="userdefined" size="10" readonly="readonly"/>
    </display:column>
</display:table>

I have created a button to make it editable...

<input type="button" value="Make Editable" class="makeEditable" />

I dont know why but its not working...no action happen

like image 260
promil pandey Avatar asked Apr 30 '26 04:04

promil pandey


1 Answers

For html input text field:

<input id="name" type="text">

You can use readonly property-

$("#name").prop("readonly",true);

This will make text field uneditable.

To make it editable :

$("#name").prop("readonly",false);
like image 53
Anshul Bisht Avatar answered May 02 '26 05:05

Anshul Bisht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!