Search code examples
pythonhtmlbottle

How add python if statement to onchange event in html


Hello

My example string with html code:

x =  '''<input type="text" name="firstname">
<input type="text" name="firstname1">
        <input type="text" name="firstname2">
      <input type="text" name="txt"  onchange="myFunction()">   
<input type="submit" value="Submit">

<script>
function myFunction() {
        ''' --->python code--->if request.forms.get('txt'):
return x= "ok"
'''

}
</script>'''

How can i do something like that?

all this things need to happend before submit


Solution

  • '''<input type="text" name="firstname">
    <input type="text" name="firstname1">
    <input type="text" name="firstname2">
    <input type="text" name="txt"  onchange="myFunction()">   
    <input type="submit" value="Submit">
    
    <script>
    function myFunction() {
     {}
    }
    </script>'''.format(THE PYTHON CODE THAT EVALUATE TO TEXT)