0
<!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>

In this code the textbox mytext is responsive to changes in the dropdown but the dropfunc() should make changes in the django form variable distance as well. Please suggest what I am doing wrong. In forms.py I have defined text data as follows:

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

7
  • a label element has no value property. and an option element has no text property ... perhaps you're looking for element.textContent? Commented Feb 12, 2018 at 5:41
  • stackoverflow.com/questions/11569967/… This link solves a similar query for reference. Commented Feb 12, 2018 at 5:42
  • @JaromandaX I want to change the value of text_data in the django form. Commented Feb 12, 2018 at 5:50
  • oh - well if that other question doesn't help, then I have no other suggestions Commented Feb 12, 2018 at 5:51
  • put {{form.text_data}} in <span class="xyz"> than inside dropfunc() change text for class xyz Commented Feb 12, 2018 at 7:06

0

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.