0

I wanted to make the disabled attribute false, but it doesn't work. here is my code. here ins my base.html

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="{% static 'css/duty.css' %}">
    <script src="{% static 'js/duty.js' %}"></script>
    <title></title>
</head>
<body>
{% block content %}
{% endblock %}

</body>
</html>

here is my duty.html

{% extends 'base.html' %}

{% block content %}
    <h1>duties and details for TA</h1>
    <p>#student:{{ course.capacity }}</p>
    <form>
        <table border="2" bordercolor="black" width="800" height="500" cellspacing="0" cellpadding="5">
            <tr>
                <th>classification</th>
                <th>times</th>
                <th>teaching activity</th>
                <th>Approx. hours/student</th>
            </tr>
            <tr>
                <td rowspan="3">Lab</td>
                <td rowspan="3"><label><input class="duty" type="text" disabled="disabled" value="{{ taDuty.labNumber }}"></label>
                </td>
                <td>preparation</td>
                <td><label><input class="duty" type="text" disabled="disabled" value="{{ taDuty.preparationHour }}"></label></td>
            </tr>
        </table>

        <button onclick="modification()">modify</button>
        <button type="submit">save</button>
    </form>
{% endblock %}

here is my duty.js

function modification() {
    let node = document.getElementsByClassName('duty');

    for (let i = 0; i < node.length; i++) {
        node[i].disabled = false;
    }
}

my javascript function can be called. I tried to add alert() and it works, but the disabled attributed can't be set false. I don't know why. Thank you for any help!

tong zhao
  • 3
  • 1

1 Answers1

0

Have a look at this, to enable the input field you can't just set elm.disabled = false.

Try using removeAttribute()

function modification() {
    let node = document.getElementsByClassName('duty');

    for (let i = 0; i < node.length; i++) {
        node[i].removeAttribute("disabled");
    }
}
GTBebbo
  • 1,198
  • 1
  • 8
  • 17