Javascript变量未传递给Django表单textarea

时间:2018-02-12 05:38:01

标签: javascript django django-forms django-templates

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function dropfunc(){
        var s = document.getElementsByName('parameters')[0];
        var text = s.options[s.selectedIndex].text;
        document.getElementById("mytext").value = text;
        document.getElementById("distance").value = text;
    }
</script>
    <form action="/summarize_text/" method="post" enctype="multipart/form-data">
    {% csrf_token %}
    <p><b> Text Summarizer</p></b>
    <select name = "parameters">
        <option>Sentence1</option>
        <option>Sentence2</option>
        <option>Sentence3</option>
        <option>Sentence4</option>
    </select>
    <input type="button" onclick="dropfunc()" value="Submit">
    <input type="text" id="mytext">
    <div class="fieldWrapper">
        <label id="distance">Sentence</label>
        {{form.text_data}}
    </div>
    </form>
</body>
</html>

在此代码中,textbox mytext响应下拉列表中的更改,但dropfunc()也应该在django表单变量距离中进行更改。请告诉我我做错了什么。在 forms.py 中,我按如下方式定义了文本数据:

text_data = forms.CharField(max_length=20000000, widget=forms.Textarea())

0 个答案:

没有答案