1

I have here a html code inside the javascript one and it will append that on my modal, my question is how can I set to readonly=false property in order textbox to be enabled. I'm trying jquery but it's not working. The group of textboxes must be enabled when calling the class.

<script>
  var html;
 for ( x=0 ; x < 5 ; x++)
  {
    html +=' <input type="text" class="changeintofalse" readonly/>';
  }

  $('#details_info').html(html);
  $('#itemsModal').modal('show');
</script>
1
  • Note that you have some syntax errors. The parentheses go around the variable declarations in the for: for (var x = 0; x < 5; x++) {. Also in your HTML string >\'; needs to be />'; Commented Mar 4, 2020 at 9:03

1 Answer 1

3

How can I set to readonly=false property in order textbox to be enabled

There is no readonly="false" setting. If the readonly attribute exists on the element, with any value, then the field will be readonly.

If you want to make the element editable again you need to remove that attribute. Using jQuery the best practice would be to use prop():

$('#foo').prop('readonly', false);

However using removeAttr() will work too:

$('#foo').removeAttr('readonly');
Sign up to request clarification or add additional context in comments.

3 Comments

i already tried, but i think jquery is not working, when my html code is inside of javascript. but thanks for the help.
For this to work you need to either place the HTML you generated in to a jQuery object, or append it to the DOM first and then perform this action. Either way, it works.
No problem, glad to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.