Forums

addlistener event gives error

This code gives me an error Keyword not found e. Works fine in non pythonanywhere environment.

<form action="/main" method="POST">
        <p style="font-size:24px;">1. Type in <font color=”green”>GREEN</font> letter(s) e.g *LO** :</p>
        <p style="font-size:24px;"><input id="text" style="font-size:24px;" type="text" name="word" />
        <img src="{{ url_for('static',filename='Asterisk.png')}}" width="32" height="32" name="button" id="button" onclick="star()" /></p>

......

<script type="text/javascript">
    document.getElementById("button").addEventListener('click', function (e) {
    e.preventDefault();
    var text = document.getElementById('text');
    text.value += '*';
    });
</script>

Where do you see that error?

its pointing to : document.getElementById("button").addEventListener('click', function (e) the e.

Error running WSGI application 2022-04-20 18:55:22,624: KeyError: '\n e' 2022-04-20 18:55:22,625: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2069, in call 2022-04-20 18:55:22,625: return self.wsgi_app(environ, start_response) 2022-04-20 18:55:22,625: 2022-04-20 18:55:22,625: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2054, in wsgi_app 2022-04-20 18:55:22,625: response = self.handle_exception(e) 2022-04-20 18:55:22,625: 2022-04-20 18:55:22,625: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2051, in wsgi_app 2022-04-20 18:55:22,625: response = self.full_dispatch_request() 2022-04-20 18:55:22,625: 2022-04-20 18:55:22,625: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1501, in full_dispatch_request 2022-04-20 18:55:22,626: rv = self.handle_user_exception(e) 2022-04-20 18:55:22,626: 2022-04-20 18:55:22,626: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1499, in full_dispatch_request 2022-04-20 18:55:22,626: rv = self.dispatch_request() 2022-04-20 18:55:22,626: 2022-04-20 18:55:22,626: File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1485, in dispatch_request 2022-04-20 18:55:22,626: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) 2022-04-20 18:55:22,626: 2022-04-20 18:55:22,626: File "/home/shabirdewji/mysite/flask_app.py", line 52, in adder_page 2022-04-20 18:55:22,626: return '''

here is the code:

    <html>
        <head>
            <title>WORDLE HELPER</title>
        </head>
        <body bgcolor="#F0F8FF">
        <h1><font color="green">W<font color="black">O<font color="green">R<font color="black">D<font color="green">L<font color="black">E HELPER</h1>
            <form method="post" action=".">
                <p style="font-size:24px;">1. Type in <font color=”green”>GREEN</font> letter(s) e.g *LO** :</p>
                <p style="font-size:24px;"><input style="font-size:24px;" type="text" id="text" name="word" />
                <img src="https://www.pythonanywhere.com/user/shabirdewji/files/home/shabirdewji/mysite/Asterisk.png" width="32" height="32" name="button" id="button" onclick="star()" /></p>
                <p style="font-size:24px;">2. Type in <strong>BLACK</strong> letters :</p>
                <p style="font-size:24px;"><input style="font-size:24px;" type="text" name="nword" /></p>
                <p style="font-size:24px;">3. Type in the YELLOW letters :</p>
                <p style="font-size:24px;"><input style="font-size:24px;" type="text" name="must" /></p>
                <p style="font-size:24px;">4. OPTIONAL: Type in the YELLOW letters and their poistion.
                For example, you have an R in the 3rd place, then enter <strong>r3</strong>.
                Another example, you have R in the 3rd and M in the 5th (both YELLOW), enter <strong>r3m5</strong> :</p>

                <p style="font-size:24px;"><input style="font-size:24px;" type="text" name="sword" /></p>
                <p style="font-size:34px;"><input style="font-weight: bold;font-size:30px; color:green" type="submit" value="Start the search" /></p>
            </form>
        <script type="text/javascript">
            document.getElementById("button").addEventListener('click', function (e) {
            e.preventDefault();
            var text = document.getElementById('text');
            text.value += '*';
            });
        </script>

It's not the code that is causing that. It looks like the problem is in /home/shabirdewji/mysite/flask_app.py