Once again I am ‘dabbling’ in the dark art of javascript and jQuery without much of a clue as to what I’m actually doing. All I know is that I managed to get my code to function by cribbing bits of other code and modifying it a bit, and after a lot of cursing, it worked…. in a fashion.
Below is a piece of my code, which correctly builds and displays a dynamic selectbox with values returned from a mysql query. When the user selects one of the items from the list, the code successfully runs a function which displays a map associated with that item.
What I ACTUALLY need it to do is also run the code to display the map for the default/top item returned by the query first, and THEN whenever a new item is selected it should run the function to display the newly selected map.
I hope the explanation has been clear enough, but feel free to chastise me if not.
Many thanks,
Rob.
$(document).ready(function() {
$('#selecthere').load('/temp/php_script.php?r='+ random, function ()
{ //callback
$('select', this).change(function () { //catch onchange event of select
//call your function here, pass the selected value
initialize($(this).val());
});
});
});
(Edited in light of comments below.)
If I understand,
initialize(val)is the function that draws the map associated withval, and you want to run it when the page loads withvalbeing whatever is in the select box by default. To do this, you could just add the function call in yourreadyfunction as such:Hope I understood.