0
Hello, I’m a beginner in php and javascript and I’m having trouble creating iterative tables.
In my case, I have an initial table:
When selecting the line that I want to check in more detail the accidents (in this case the option is São Paulo), a new table is opened in a dialog box:
So far so good, I’ve been able to identify which line I’m clicking but I can’t pass this information to php code, because it would have to access the database and bring the information concerning the selected city.
Any hint?
<script>
$(document).ready(function(){
$("tr[rel=modal]").click( function(ev){
// Efeitos de transição para aparecer a janela semelhante um alerta
ev.preventDefault();
var cidade = $(this).attr("id"); //Essa variavel carrega a informação da linha selecionada
}
</script>
<tr href="#janela1" rel="modal" class="read checked" id="<?=$linha['cidade']?>">
<a id="<?=$linha['cidade']?>"></a>
<td><?=$linha['cidade']?></td>
<td><?=$linha['acidentes']?></td>
<td><?=$linha['fatais']?></td>
<td><?=$linha['ano']?></td>
<td><?=$linha['meta']?></td>
<td><?=$linha['farol']?></td>
</tr>
I edited the question because I believe it makes it easier to understand my doubt.
I tried here in a similar way, but you need to give F5 so that the selected option is enabled, if not F5, stays in the selected option before refreshing the page. $(Document). ready(Function(){
$("tr[rel=modal]"). click( Function(Ev), Ev.preventDefault();
var indicator = $(this). attr("id"); $("#window12"). load('valida2.php', {acc:indicator}); in valida2.php put $_SESSION[indicator]=$_POST['acc'];
Got any more tips? I’m racking my brain here
I was able to put the modal window to open an external page. Now I’m having trouble with this modal window, the first time it opens her navigation tabs don’t work, the second time they work normally. This repeats, odd attempt does not open and even opens. Another detail is in the mask, that after 4 clicks she gives a bugger, getting missing and appearing a few times. I’ll edit the topic for better visualization of the code.
$(document).ready(function(){
$("tr[rel=modal]").click( function(ev){
ev.preventDefault();
var indicador = $(this).attr("id");
$("#janela12").load('tabelas.php', {acc:indicador});
var id = $(this).attr("href");
var alturaTela = $(document).height();
var larguraTela = $(window).width();
//colocando o fundo preto
$('#mascara').css({'width':larguraTela,'height':alturaTela});
$('#mascara').fadeIn(300);
$('#mascara').fadeTo(300,0.8);
var left = ($(window).width() /2) - ( $(id).width() / 2 );
var top = ($(window).height() / 2) - ( $(id).height() / 2 );
$(id).css({'top':top,'left':left});
$(id).show();
});
$('#mascara, .fechar').click(function(e){
if( e.target !== this )
return;
$('#mascara').fadeOut(30);
$('.window').fadeOut(30);
$('#mascara').hide();
$('.window').hide();
});
});
<div id="mascara"></div>
<div class="window" id="janela1">
<div id="janela12"></div>
Possible duplicate of How to pass variables between PHP pages via Javascript?
– MoshMage
Possible duplicate of I can make Javascript write PHP?
– Amadeu Antunes