Home > database >  How to get updates from the input field in Django
How to get updates from the input field in Django

Time:01-11

I have this code in template

{% block content %}
<script>
    function onChange(event) {
        console.log("log")
    }
</script>
<h3>List</h3>

<input type="text" placeholder="Filter by..." onchange="onChange(event)" value={{ searching_value }} >

But it doesn't seem to work..

CodePudding user response:

As @schillingt mentioned, the argument of onChange is a Event. So you should treat it like one :)

{% block content %}
<script>
    function onChange(event) {
        console.log(event.target.value)
    }
</script>
<h3>List</h3>

<input type="text" placeholder="Filter by..." onchange="onChange" value="{{ searching_value }}"/ >

CodePudding user response:

The value from the event should be accessed via event.target.value as per the MDN docs. You can't access this.value how you are. onChange should accept an event argument and you pass the reference to the function for the onchange attribute.

  •  Tags:  
  • Related