1
votes

I'm trying to send the user selected date from the calendar to python but i'm seeing errors. Requirement is user selects a date from the calendar-->selected date sent to python -->SQL query retrieves the results from db using the date-->show the results back to user on webpage.

    $(function() {
    $( "#datepick" ).datepicker();
    });
    $(document).on("change", "#datepick", function () {
    var newdate= $("#datepick").datepicker({ dateFormat: "dd-mm-yy"}).val(); 
    alert(newdate);
    $("#submitdate").submit();
    });

This is the form I'm using :

    <form id="submitdate" action="/date" method="POST">
    <b>Date:</b> <input type="text" id="datepick" placeholder="Select Date">
    </form>

After selecting the date from the calendar, i can see the selected date alert and once i click 'ok', the control is sent to new page(/date) but seeing the below error : The browser (or proxy) sent a request that this server could not understand.

Please suggest how to modify the code. I'm trying to capture this selected date in the python code : @app.route('/date',methods=['GET','POST']) def formval(): if request.method=='POST': dateval = request.form['datepick']

1

1 Answers

0
votes

The input element must have a name attribute in order to be included in the submit request:

<form id="submitdate" action="/date" method="POST">
<b>Date:</b> <input type="text" id="datepick" name="datepick" placeholder="Select Date">
</form>