0

I'm trying to access an array I defined in my HTML/Javascript class view.html of a Flask application.

view.html

<div class="container">
    <input type="checkbox" class="checks" value="NEWS_AND_MAGAZINES"> NEWS_AND_MAGAZINES <br/>
    <input type="checkbox" class="checks" value="ART_AND_DESIGN"> ART_AND_DESIGN <br/>
    <input type="checkbox" class="checks" value="AUTO_AND_VEHICLES"> AUTO_AND_VEHICLES <br/><br/>

    <a href="#" onclick="getValue();return false;" class="btn btn-success">Submit</a>

</div>

<script>
    function getValue() {

        var checks = document.getElementsByClassName('checks')
        var chosen_categories = []

        for (i = 0; i<3; i++) {
            if (checks[i].checked === true) {
                chosen_categories.push(checks[i].value)
            }
        }
        alert(chosen_categories);
    }

</script>

main.py :

@app.route('/view')
def view():
    return render_template("GooglePlayStore/view.html")

I want to access the chosen_categories array to use it with BeautifulSoup and other python libraries that are easier to use with Python. Thank you

userHG
  • 567
  • 4
  • 29
  • Why would you use BeautifulSoup here? What would you be using it for? – Daniel Roseman May 15 '19 at 19:26
  • Problem: Flask runs on the server-side, while Javascript runs on the client-side. The only way to make them interact would be to send requests back and forth. There's probably some Javascript library you can use for this purpose, if you want to prettify data for the user - or you might need to create a new endpoint in Flask and have the Javascript send requests to it. – Green Cloak Guy May 15 '19 at 19:29
  • You can use AJAX to asynchronously send the data to flask, without having to reload your page. More details [here](https://stackoverflow.com/questions/52870184/get-data-from-html-and-do-some-operation-on-it-and-pass-the-data-back-to-the-f/52883461#52883461) – Tobin May 15 '19 at 21:17

0 Answers0