I have the following code, with which i try to dynamically pass my arguments between pages
<script type="text/javascript">
function buildAndSubmitForm(index){
<? $args = 't='.$team.'&s='.$season.'&l='.$league.'&f='.$flag;
$inputs = '';
foreach($games as $game)
$inputs .= '<input type="checkbox" name="games[]" id="games[]" value="'.$game.'" checked="checked" />';
?>
var form = '<?='<form name="myForm" id="myForm" action="scr'?>';
form = form.concat(index);
form = form.concat('<?='.php?'.$args.'" method="post">'.$inputs.'</form>'?>');
$('#formDiv').html(form);
$('#myForm'.concat(index)).submit();
}
</script>
<div style="display: inline">
<div name="formDiv" id="formDiv" style="display: none;"></div>
<a href="#" onclick="buildAndSubmitForm('a')">Home Stats</a>
<a href="#" onclick="buildAndSubmitForm('b')">Visit Stats</a>
<a href="#" onclick="buildAndSubmitForm('c')">Wins VS Losses</a>
<a href="#" onclick="buildAndSubmitForm('d')">Home VS Visit</a>
<a href="#" onclick="buildAndSubmitForm('e')">Overall</a>
</div>
The problem is that when i click at a certain speed (click on a link, then as it is getting submitted (like a half a second - second later) I click another link), my form gets submitted empty to the second link I've clicked. Why is this happening?
EDIT: Tryed to do the following instead:
<div style="display: inline">
<a href="<?php echo "scra.php?t=$team&s=$season&l=$league&f=$flag"; foreach($games as $game) {echo "&game=$game"; }?>" >Home Stats</a>
<a href="<?php echo "scrb.php?t=$team&s=$season&l=$league&f=$flag"; foreach($games as $game) {echo "&game=$game"; }?>" >Visit Stats</a>
<a href="<?php echo "scrc.php?t=$team&s=$season&l=$league&f=$flag"; foreach($games as $game) {echo "&game=$game"; }?>" >Wins VS Losses</a>
<a href="<?php echo "scrd.php?t=$team&s=$season&l=$league&f=$flag"; foreach($games as $game) {echo "&game=$game"; }?>" >Home VS Visit</a>
<a href="<?php echo "scre.php?t=$team&s=$season&l=$league&f=$flag"; foreach($games as $game) {echo "&game=$game"; }?>" >Overall</a>
</div>
EDIT2: None of the solutions work yet.