Tom C. Tom C. - 1 year ago 75
MySQL Question

Dropdown menu populated from sql with url redirect

For the three dropdown menu I have the sql table as follows:

sql city table

I'm trying to use:

$(document).ready(function() {

How do I acomplish my goal so when the city is selected it redirects to the corresponding url?

Answer Source

You have to add your URL in your option. It shoudl work if you put the url in the value but I suggest you to use a data-attributes

$("#city_id").append("<option data-url=\""+ value.city_url+"\" value=" + value.city_id +">""</option>"); 

it should render you something like

<option data-url="" value=1>Miami</option>

Then you can redirect to this attribute (according your select has a id="city_id")

$(document).ready(function() {

Code is not tested but you should understand the way to do it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download