I am working on web cgi application using python. Where I have two dropdowns whose options are rendered from list. Now I want to dynamically updated content of the second dropdown based on the first dropdown value.
All the code is written in Python including HTML. I am able to call onchange event on the first dropdown and get the selected value into Javascript object, however I want to assign it to python variable so that I can populate the second dropdown based on the selected value.
    <label for="staticEmail" class="col-sm-2 col-form-label">State:</label>
    <div class="col-sm-6">
      <select name="state" class="form-select" autofocus id="select_facility" onchange="selectFacility()">
      <option value="XX">Select Facility</option>''')
  for r in stateList:
    print('<option value="'+str(r)+'">'+str(r))
  print('</select>')
  print('</div>')
  print('</div>')
  print('''<div class="mb-3 row">
    <label for="staticEmail" class="col-sm-2 col-form-label">Facility Name:</label>
    <div class="col-sm-6">
      <select name=state class="form-select" >
      <option value=XX>Select Facility</option>''')
  for r in facList:
    print('<option value="'+str(r['state'])+'|'+r['facility_npi']+'">'+r['name']+', '+r['city']+', '+r['state'])
  print('</select>')
  print('</div>')
  print('</div>')```
And Javascript code having onchange method defined is as follows:
```print('''<script>''')
print('function selectFacility(){return document.getElementById("select_facility").value}')
print('</script>''')```
But I am unable to obtain the selected value into Python variable.
 
     
    