Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Add href in OnClick attribute in html form

I want to redirect to the python flask route home after showing the alert window.

<input type="submit" value="Register" onclick="call(); log();"></input>

Here are both functions.

<script>

  function call()
  {
    window.alert("Congragulations! You Registerd Sucessfully ");
  }
  
</script>
<script>

  function log()
  {
    <a href="/home" > </a>
  }
  
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understood your project correctly, you want to forward the user after he has registered. At the same time, a message should appear that the process was successfully completed.

I think your javascript approach is not sufficient for this, since the data must first be sent from the client to the server so that the process is complete. Here the inputs should also be validated and will likely be processed or stored in some way.

I have written a small example for you, which accepts form data and checks it. If the verification is successful, the user is redirected and a message appears. To forward and display the message I use redirect and flash from the flask package.

Python Flask

import re
from flask import Flask
from flask import (
    flash,
    redirect,
    render_template,
    request,
    session,
    url_for
)

app = Flask(__name__)
app.secret_key = b'your secret here'

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        username = request.form.get('username')
        if username and re.match(r'^[a-z0-9\_\-]+$', username, re.IGNORECASE):
            session['username'] = username
            flash('Congragulations! You Registerd Sucessfully.')
            return redirect(url_for('home'))
    return render_template('register.html')

HTML (index.html)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <nav>
      <ul style="list-style: none;">
        <li><a href="{{ url_for('register') }}">Register</a></li>
      </ul>
    </nav>

  {% with messages = get_flashed_messages() -%}
    {% if messages -%}
    <ul class="flashes">
      {% for message in messages -%}
      <li>{{ message }}</li>
      {% endfor -%}
    </ul>
    {% endif -%}
  {% endwith -%}

    <h1>Welcome {{ session.get('username', 'Guest') }}!</h1>
  </body>
</html>

HTML (register.html)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Register</title>
  </head>
  <body>
    <form method="post">
      <div>
        <label for="username">Username</label>
        <input type="text" name="username" id="username" />
      </div>
      <input type="submit" value="Register" />
    </form>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!