PDA

View Full Version : show list based on value clicked



jarv
02-02-2011, 11:31 AM
hi,
the following function shows a list of Counties populates by a PHP page:


$.getJSON('http://www.mypubspace.com/dashtest/countyjson.php', function(data){
var myhtml = '<ul>';
for(i=0; i<data.length; i++) {
myhtml += '<li>' + data[i].County + '</li>';
}
myhtml += '</ul>';
$("#countyshow").html(myhtml);

});

I would like to now, when a user clicks on a County, they are shown a list of pubs based on that County (so, I'll create a new PHP page WHERE County = 'County' or something?!)

at the moment, when a user clicks on a County this function is passed:


function gopublist(event)
{
var stackLayout = document.getElementById('stackLayout').object; // Replace with id of StackLayout
stackLayout.setCurrentView('view4');
}


So, passing a value through so I can modify the SQL in the PHP page to filter the counties?!

Please help?

lecisco
02-02-2011, 09:28 PM
How are you getting the function to be called? I don't see an "onclick=" or anything. why not add an onclick to your <li> tags to look something like this:

myhtml += '<li onclick=\"mymethod('+data[i].Country+');\">' + data[i].Country + '</li>';

jarv
02-03-2011, 11:27 AM
excellent thanks, and then calling that mymethod(); function?

lecisco
02-03-2011, 05:06 PM
Well you'd make 'mymethod()' be whatever you need it to be, like this:


function mymethod(country) {
var stackLayout = document.getElementById('stackLayout').object;
stackLayout.setCurrentView(country);
}

Just make sure the parameter you have it passing is the right kind of the setCurrentView() call.

jarv
02-09-2011, 02:35 AM
ok, so this is sort of working... I can see that it is trying to be passed through...


so, if I select Aberdeenshire it will error:

Cannot find variable: Aberdeenshire


Please help?!

thanks, nearly there!