[Fixed]-How to pass value from html file to views.py file?

1👍

You can use Ajax. This is other way to do it

base.html

<form method="POST" name="your_form" action="{% url 'your_app:your_url' %}">
    <input type="text" name="vat" id="vat1" placeholder="Please Enter 10 digits number">
</form>
<script type="text/javascript">
    $(document).ready(function(){
        $('#vat1').keyup(function(event){
            if (event.which == 13 || event.keyCode == 13){
                if ($(this).val().length == 10){
                    $('your_form').submit();
                }else{
                    // Show message if the text length is lesser than 10
                }
            }
        });
    });
</script>

Leave a comment