Combobox + UF + City + Mysql + Javascript

Asked

Viewed 573 times

1

I have the following question: I have a project in Java JSP and do not know how to select the UF and City combo update as selected before. below I have an example with fixed data, but I want to do in mysql, I want to know how to run the select in the table of the database. I need an example in my project

I’ve done everything I can and I don’t know how to move forward.

I got it from here done in mine.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<script type='text/javascript'>
    window.onload = function () {
        BindEvent();
    }
    function BindEvent()
    {
        var elemToBind = document.getElementById("uf");
        elemToBind.onchange = function () {
            SetSel(this);
        }
    }
    function SetSel(elem)
    {
        var secondCombo = document.getElementById("cidade");
        secondCombo.value = elem.value;
    }
</script>
<body>
    <select id="uf">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    </select>
    <select id="cidade">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    </select>
</body>

I saw that in this other topic there is what I need but I don’t know php needed to make it work with jsp and doing the consultation in the right bank

How to select an option in one <select> and load related data in another?

  • 1

    Welcome to Stackoverflow! Make a tour to better understand how this community works. Next, edit your question better explain what your doubts are.

  • Cristiano will need to use AJAX (know what it is?) or generate the page with all the possibilities in an object to use in Javascript to popular this second select. What do you want to do?

  • I know what it is but I’ve never used it, I don’t know what I call it inside the jsp. It would take an example for me to get a sense of how to start

  • Managed to Resolve?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.