I'm studying Json and the Jquery change event. What I need is the following When the user opens the page already has results. (no select all checked)
The html comes empty and only works when I change the select to some city.
var cidade = "";
$('select').on('change', function() {
cidade = this.value
var url = "http://meusite?&cidade="+cidade;
//jsonrodando
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><select><option>cidades</option><optionvalue" " selected=" ">todas</option>
<option value"1"> cidade1</option>
<option value"2">cidade2</option>
</select>
json works perfectly when I select the correct city in the select.
But it does not come pre loaded with all. (When the variable "city" in the URL comes empty they all appear)
It should work like this: Open page comes all cities. (It does not work).
User changes to select the city, and the city appears (this works perfect);
What needs to be changed in the code?