I've got a list of items that have different data values that I'm trying to return on a click event. I can't seem to pass the value from the click event to the parent function. I may just be doing this all wrong. I just need the data value from each click event to replace the value of my systemName variable. Can someone help me out here?
function getSystemName(){
var systemName = '';
$('.pulldown li').bind('click', function(){
var systemName = '';
var systemName = $(this).find('a').data('value');
console.log(systemName);
});
return systemName;
}
// Edit: I should probably explain that I'm trying to get that value from the click event to update content on the page via jquery .load so perhaps like mentioned below....I'm not doing this properly because I can log the systemName properly on click but it doesn't seem to update the page content. Here is the entire code block.
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='.../images/130.gif' alt='loading...' align='middle' />";
var loadUrl = ".../content.php";
var getSystemName = (function(){
var systemName = '';
$('.pulldown li').bind('click', function(){
systemName = $(this).find('a').data('value');
console.log(systemName);
});
return function() { return systemName };
})();
$("#results")
.html(ajax_load)
.load(loadUrl, "ki_systems=" +getSystemName());
systemNamethree times. Is that intended?getSystemName()function: just put your.load()statement inside the click event handler and run the.bind()in your document.ready. (Man did I ever guess wrong what you were talking about, though I think my answer is reasonable for your original question as asked.)