javascript - Set variable across JQuery loaded pages -
i have page has 3 sections. on left static menu
e.g.
<a href="#" class="actionlink" id="newfile"><li>new file</li></a>
this can start new actions e.g.
$('.actionlink').click(function() { var folderid; // trying set id here var filename = $(this).attr('id'); $("#myaction").load('/ajax/actions/' + filename + '.php?folder_id=' + folderid); })
so, loads /ajax/actions/newfile.php
in middle page loaded using jquery .load()
. within page in middle series of folders have id. on click, these folders display contents shown on right of page.
e.g.
<span id="12" class="folder active99">music</span> $('.folder').click(function() { var folderid = $(this).attr('id'); $("#myaction").load('/ajax/actions/links.php?folder_id=' + folderid); })
when clicked shows contents on right. note variable folderid. works ok.
what happen when folder selected in middle, changes folderid
variable on left hand menu when new action chosen corresponds folder supposed to.
i've tried setting variable everywhere i.e. in sections var folderid;
whatever try doesn't carry variable around.
is possible or there better way this? going wrongly?
to summarize: when click folder in middle need add variable left menu.
update
this code use:
$(document).ready(function(){ var folderid = ''; $('.actionlink').click(function() { var filename = $(this).attr('id'); $("#myaction").load('/ajax/actions/' + filename + '.php?folder_id=' + folderid); }); $('.folder').click(function() { $('.folder').removeclass('active99'); // remove other <span>s $(this).addclass('active99'); // add onto current var folderid = $(this).attr('id'); $("#myaction").load('/ajax/actions/links.php?folder_id=' + folderid); }); });
i've changed things middle section included opposed using .load()
still not working
you're dealing variable scope issue, must declare folderid variable outside (at greater scope) it's available both actions:
$(document).ready(function(){ var folderid = ''; $('.actionlink').click(function() { var filename = $(this).attr('id'); $("#myaction").load('/ajax/actions/' + filename + '.php?folder_id=' + folderid); }); $('.folder').click(function() { folderid = $(this).attr('id'); $("#myaction").load('/ajax/actions/links.php?folder_id=' + folderid); }); });
Comments
Post a Comment