How can I remove the readonly
attribute when the Edit
button is clicked? My codes is working if clicked but after one second the input form is back to readyonly
.
<input class="form-control" name="fullname" value="<php echo $fullname; ?>" readonly/>
<button class="btn btn-primary" id="btnEdit" > edit </button>
<script>
$(document).ready(function(){
$('#btnEdit').click(function(){
$("input[name='fullname']").attr("readonly", false);
});
});
</script>
How can I remove the readonly
attribute when the Edit
button is clicked? My codes is working if clicked but after one second the input form is back to readyonly
.
<input class="form-control" name="fullname" value="<php echo $fullname; ?>" readonly/>
<button class="btn btn-primary" id="btnEdit" > edit </button>
<script>
$(document).ready(function(){
$('#btnEdit').click(function(){
$("input[name='fullname']").attr("readonly", false);
});
});
</script>
Share
Improve this question
edited May 28, 2016 at 9:31
Manfred Radlwimmer
13.4k13 gold badges55 silver badges64 bronze badges
asked May 28, 2016 at 9:06
expert123expert123
376 silver badges11 bronze badges
5
- button lead to a form submit? – gu mingfeng Commented May 28, 2016 at 9:11
- I would think that you have some other code which make the field read only. You better to find what code is responsible for making the fields read only. Maybe the form gets updated with ajax request? – Mikhail Chibel Commented May 28, 2016 at 9:14
-
api.jquery./removeAttr -
readonly
is a boolean attribute meaning its presence is all that is needed to work. – Niet the Dark Absol Commented May 28, 2016 at 9:15 -
removeAttr
is not the right method. Use .prop instead. Example$(element).prop('readonly', false)
. – php-dev Commented May 28, 2016 at 9:24 - Possible duplicate of how we add or remove readonly attribute from textbox on clicking radion button in cakephp using jquery? – Rajesh Commented May 28, 2016 at 9:29
2 Answers
Reset to default 4You should use jQuery removeAttr
$(document).ready(function(){
$('#btnEdit').click(function(){
$("input[name='fullname']").removeAttr( "readonly" );
});
});
try this you have to use removeAttr reference link
<script>
$(document).ready(function()
{
$('#btnEdit').click(function()
{
$("input[name='fullname']").removeAttr("readonly");
});
});
</script>